I want to be able to tap a switch and have it slide to the other side. Right now that switch is a prefab with my code attached. When I add copies of that prefab all of them move not the individual one I clicked.
// 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);
}
}