- Home /
Question by
GoGamingJoe · Apr 19, 2014 at 06:50 PM ·
ontriggerenter
Why Is My On Trigger Enter Not Working
using System.Collections.Generic;
public class CamelAI : MonoBehaviour {
public Waypoint[] Waypoints;
public static CamelAI Instance;
public Vector3 MoveVector = Vector3.zero;
public bool GenarateVector;
public GameObject MuliPlayer;
void Awake(){
Waypoints = FindObjectsOfType<Waypoint> ();
Instance = this;
}
void Start(){
MuliPlayer = null;
}
//THE MOVEMENT TO THE VECTOR/POSITION----------------------------------------------
void Update(){
Waypoint wp = FindClosestWaypoint (transform, Mathf.Infinity);
float x = wp.transform.position.x;
float z = wp.transform.position.z;
float y = wp.transform.position.y;
MoveVector = new Vector3 (x, y, z);
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (MoveVector - transform.position), 1f * Time.deltaTime);
transform.position = Vector3.Slerp (transform.position, MoveVector, 0.0005f * Time.deltaTime);
//Player Controller Part----------------------------------------------------------------
// End Player Controller Part----------------------------------------------------------------
}
void OnTriggerEnter(Collider other){
if(other = GameObject.FindGameObjectWithTag("Player"){
MuliPlayer = other.gameObject;
}
}
//THE END OF MOVMENT------------------------------------------------------------------
public Waypoint FindClosestWaypoint(Transform obj, float Range){
Waypoint curClosest = null;
float distance = Mathf.Infinity;
Vector3 Pos = obj.position;
foreach (Waypoint wp in Waypoints) {
Vector3 diffrence = wp.transform.position - Pos;
float magnutude = diffrence.sqrMagnitude;
if(magnutude < distance){
curClosest = wp;
distance = magnutude;
}
}
return curClosest;
}
void OnDrawGizmos(){
Gizmos.DrawLine(transform.position, FindClosestWaypoint(transform, 100000).transform.position);
}
}
The Error says Unexpected symbol `{' But if I remove the { it says thet MuliPlayer Could not be found. What is going on;
Comment
Best Answer
Answer by robertbu · Apr 19, 2014 at 06:52 PM
You are missing a ')' to close off your 'if' statement. Add a ')' just before the '{'
For future posts of syntax errors, please include a copy of the error from the console. It gives us helpful information like the line number of the error and some of the stack trace.