- Home /
Activating a single Prefab with the same tag using Raycast.
I've only seen one related question to this, but it didn't help me to understand why this isn't working for me. Essentially, I'm creating a puzzle game where you click mirrors to rotate them 90 degrees. The raycast is working, the rotation is working, yet for some reason when the click occurs, -every- instance of the prefab rotates. I know I need to add something to make the rotation only effect what the raycast -actually- hit, yet it's being...finicky. This is what I've got so far.
Ray ray;
RaycastHit hit;
private float angle;
void Start () {
// Initialise ray
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
}
void Update () {
Selection();
}
void Selection() {
if(Input.GetKeyDown(KeyCode.Mouse0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit)) {
if(hit.collider && hit.collider.tag == "Blocker") {
angle += 90f;
this.gameObject.transform.eulerAngles = new Vector3(0, angle, 0);
}
}
}
So how can I specify this code to make -only- the specific prefab hit rotate?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613173732im_/https://answers.unity.com/themes/thub/images/avi.jpg)