我希望能够点击一个开关并让它滑到另一边。现在那个开关是一个带有我的代码的预制件。当我添加该预制件的副本时,所有这些副本都会移动而不是我单击的单个副本。
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
PrintName(hit.transform.gameObject);
}
}
}
private void PrintName(GameObject go)
{
print(go.name);
transform.position += new Vector3(3, 0, 0);
}
}