Question by
austinlayne7 · May 05, 2017 at 03:59 PM ·
scripting problemmeshontriggerenterfunctions
When player enters area. Object that script is attached to walks toward the entering object(player).
hello, thank you for anyone that can help. I want it so When player enters area. The object that the script is attached to walks toward the player. Here's what I'm thinking:
void OnTriggerEnter (Collider other){
if(other.name == "Player" || other.tag == "Player"){
/*This is where I want to put the script for having the object move to the player. Although, I don't know the function. Any help is appreciated.*/
Debug.Log("Player Has Entered");
}
Thanks for the help. I just forgot the function, I thought I saw one at some point, just cant think of it. It's been bothering me for days :) .
Comment
Answer by MrCrumbl3d · May 05, 2017 at 04:35 PM
If it's enemy. it's easy. Try this.
public GameObject Player;
void OnTriggerEnter (Collider other){
if(other.name == "Player" || other.tag == "Player"){
//Object will look to the player.
transform.LookAt(Player);
//the object will move towards the player.
transform.Translate(speed*Vector3.forward*Time.deltaTime);
Debug.Log("Player Has Entered");
}
Your answer
Follow this Question
Related Questions
Easy Short kill score script not working 0 Answers
HELP the completeLevel function doesnt work (c#),why doesnt my trigger object work? 0 Answers
UV mapping on mesh with tiling texture 1 Answer
Save a script created mesh as mesh 1 Answer
End Game (Stop spawning) with OnTriggerEnter or OnCollisionEnter? 0 Answers