Question by
Brades98 · May 16, 2016 at 04:29 AM ·
c#positiontriggering animation box collider
OnTriggerEnter and Exit using Position Markers? help??
So im trying to make this door open using coliders. i can open it with a button but i need to open it like this: activate the door using the button, walk into collider and door will open automatically.
im new to unity and dont understand what im doing wrong, can someone help!
using UnityEngine; using System.Collections;
public class AutobotDoor : MonoBehaviour
{
//Components
Animator doorAnim;
//Refrences
public GameObject lightObj;
Light light;
Renderer lightRend;
public Transform platform;
public Transform[] posArr;
public int targetPos;
public float speed = 5f;
void Start ()
{
//Get Component
doorAnim = this.GetComponent<Animator>();
}
void OnTriggerEnter(Collider otherCol)
{
//check if the player emetered the trigger
if(otherCol.tag == "Player")
{
//DoStuff
platform.position = Vector3.MoveTowards(platform.position, posArr[targetPos].position, speed * Time.deltaTime);("DoorState" , true);
}
}
void OnTriggerExit(Collider otherCol)
{
//check if the player emetered the trigger
if(otherCol.tag == "Player")
{
//DoStuff
platform.position = Vector3.MoveTowards(platform.position, posArr[targetPos].position, speed * Time.deltaTime);("DoorState" , false);
}
}
x
void OpenDoor()
{
// 1) Check current state of targetPos and change it
if(targetPos == 0)
targetPos = 1;
else
targetPos = 0;
}
void Update ()
{
}
}
Comment
Answer by Brades98 · May 16, 2016 at 04:34 AM
here is wat it looks like. i just cant get it right
screen-shot-2016-05-16-at-23114-pm.png
(333.4 kB)