- Home /
Question by
Memorix101 · Jul 08, 2013 at 09:49 AM ·
gameobjectrotateclick
Rotate Clicked Gameobject / Perhab
Hello, I'm working on a memory game and my current problem is. If I click on a memory block all will turn around and not the selected one. :(
This is my code:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update(){
if(Input.GetMouseButtonDown(0)){
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit)){
if(hit.collider.tag == "Memo"){
hit.transform.Rotate(new Vector3(0,180,0));
print("Clicked Memo" + gameObject.name);
}
}
}
}
}
Comment
I could not see a problem reading your code, so I tested it. It worked fine. Only one block was flipped. Note this code should only be attached to a single game object.