Question by
ninjixfatality · Apr 19, 2018 at 10:13 AM ·
scripting problemgameobjectdisable
How to disable a script in another without Public GameObject?
I just want to disable a script that's in my player-manager. But because my enemies spawn through set active the public game object just isn't working. Can I just manually pick it out through a specific GameObject in the script?
public float lookRadius = 40f;
//public Casting stop;
Transform target;
UnityEngine.AI.NavMeshAgent agent;
Rigidbody theRigidBody;
void Start(){
target = PlayerManager.instance.player.transform;
agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
}
void Update(){
float distance = Vector3.Distance (target.position, transform.position);
if (distance <= lookRadius)
{
agent.SetDestination (target.position);
if (distance <= agent.stoppingDistance)
{
FaceTarget ();
}
if (distance < 10f) // or some distance
{
//gameObject.GetComponent<Casting>().enabled = false;
Debug.Log("nearby heyy");
}
}
}
void FaceTarget()
{
Vector3 direction = (target.position - transform.position).normalized;
Quaternion lookRotation = Quaternion.LookRotation (new Vector3 (direction.x, 0, direction.z));
transform.rotation = Quaternion.Slerp (transform.rotation, lookRotation, Time.deltaTime * 5f);
}
Comment
Your answer
Follow this Question
Related Questions
gameObject.SetActive (false); not working 2 Answers
How to instantiate a game object every time when space key is pressed 2 Answers
Hi everyone.need help with this. 1 Answer
Input Command Issues 0 Answers
Scrpits component disappears when I enter playmode 0 Answers