Hi, I’ve been having problems today with my scripts, see how it is supposed to work is that if the player is not looking it will move and if it is then it wont move, and this functions great in the editor but when I hit the build button I discovered that it just doesn’t work in builds, I have tried web player and PC -.- I don’t know what is going wrong I think it may be that the scripts are out of sync but I’ve tried invokerepeting, update, fixed update and now late update on both scripts and it is so frustrating. I have also changed code execution order, no luck ![]()
This is my script:
using UnityEngine;
using System.Collections;
public class AI : MonoBehaviour {
public GameObject Gribe;
public Transform Player;
public Transform Holder;
public bool canmove2;
AIPath path;
bool canmove;
Vector3 pos;
Vector3 tarpos;
RaycastHit hit;
void Start () {
path = Gribe.GetComponent<AIPath>();
}
void Update ()
{
pos = new Vector3(Player.position.x,Holder.transform.position.y,Player.position.z);
Holder.LookAt(pos);
if (canmove == false)
{
tarpos = Player.position - transform.position;
if (Physics.Raycast(Holder.position, tarpos, out hit))
{
if (hit.transform.gameObject.tag == "Player")
{
path.canMove = false;
}
else
{
path.canMove = true;
}
}
}
else
{
path.canMove = true;
}
}
void OnBecameVisible () {
canmove = false;
}
void OnBecameInvisible () {
canmove = true;
}
}
And this is a snippet from a asset I’m using:
public virtual void LateUpdate () {
//if (AIholder.canmove2 = false) { return; }
Debug.Log ("" + canMove);
if (canMove == true){
Vector3 dir = CalculateVelocity (GetFeetPosition());
//Rotate towards targetDirection (filled in by CalculateVelocity)
if (targetDirection != Vector3.zero) {
RotateTowards (targetDirection);
}
if (navController != null) {
navController.SimpleMove (GetFeetPosition(),dir);
} else if (controller != null) {
controller.SimpleMove (dir);
} else if (rigid != null) {
rigid.AddForce (dir);
} else {
transform.Translate (dir*Time.deltaTime, Space.World);
}
}
}
Any help would be great so I can keep my sanity ![]()