Rotate an object when two others collide?
I'm working on a door that shuts when the player hits a collider that's near it. I wrote a script that doesn't get any errors and works, but the door still wont rotate. here is the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorClose : MonoBehaviour {
public GameObject Trigger;
public GameObject Door;
public GameObject Player;
public Transform Dooor;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
Debug.Log("IT WORKS!!");
Dooor.transform.Rotate(0, 60, 0);
}
}
}
any help would be appreciated.
Answer by SFoxx28 · Jan 17, 2018 at 04:50 AM
I'm not near a computer with unity installed so I can't test this out locally but try this instead underneath the Debug.Log:
Door.transform.Rotate(0,60,0);
Make sure you pass a reference of the door object you want to rotate from the editor to the script. I think that you are rotating the transform alright but you are not rotating the door game object. Try it out and let me know if that worked.
it still doesn't work. I should have mentioned that I tried that before. the script in on the trigger if that helps.
not sure what you mean. I'm still using the script you see above except using the GameObject ins$$anonymous$$d of the transform. the Debug.Log works perfectly but it wont rotate