So I can not for the life of me figure out how to make a door move out of the way when I am walking up to it.
I watched this as a base but I think it is kinda throwing me off. I got the animations to sorta work but they the door is just moving up and down all the time. Maybe i should just make this more simple and uses forces and stuff instead of animations but this should be the easier way if I can just figure it out.
My set up right now it as fallows.
A door trigger with my script, rigid body and animation attached.
Then a door (cube) with its mesh intact parented to the trigger.
Code I have used: (in c#)
using UnityEngine;
using System.Collections;
public class DoorOpener : MonoBehaviour {
private HashIDs hash;
private Animator anim;
private GameObject player;
private int count;
void Awake ()
{
// Setting up the references.
anim = GetComponent<Animator>();
hash = GameObject.FindGameObjectWithTag("GameController").GetComponent<HashIDs>();
player = GameObject.FindGameObjectWithTag("Player");
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject == player) {
count++;
Debug.Log ("OPEN");
}
}
void OnTriggerExit (Collider other)
{
if(other.gameObject == player) {
count = Mathf.Max(0, count-1);
Debug.Log ("CLOSE");
}
}
void Update ()
{
anim.SetBool(hash.openBool,count > 0);
}
}
Also a hashID script to go along with that,
Sorry for any sloppy coding syntax
Any ideas? thanks, kindling bugging me that I can’t figure this out