天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
1.2 KiB

using UnityEngine;
using System.Collections;
using System.Linq;
using UnityEngine.UI;
public class AddItem : MonoBehaviour {
public static bool CanAdd = false;
Canvas canvas;
void Start ()
{
canvas = GameObject.Find("Canvas").gameObject.GetComponent<Canvas>();
TheAddFather = GameObject.Find("TagFather").gameObject;
}
public GameObject TheADD;
private GameObject TheAddFather;
void Update ()
{
if (CanAdd)
{
if (Input.GetMouseButton(0))
{
GameObject obj=Instantiate(TheADD)as GameObject;
obj.transform.SetParent(TheAddFather.transform);
obj.transform.localScale = new Vector3(1, 1, 1);
//Vector3 sss = .currentCamera.ScreenToWorldPoint(Input.mousePosition);
//obj.transform.position = sss;
Vector2 pos;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, canvas.worldCamera, out pos))
{
obj.transform.GetComponent<RectTransform>().anchoredPosition = pos;
}
CanAdd = false;
}
}
}
}