I’m trying to access a child script from another child’s script off the same parent. Basically I want to have it so if the gameobject runs out of health it won’t be able to move any more. My script is
using UnityEngine;
using System.Collections;
public class SkeletonAggro : MonoBehaviour {
public GameObject playersoldier;
Transform playertransform;
float runspeed = 3;
public bool fighting = false ;
public bool foundplayer = false;
private skelattack SkelAttack;
private AttackingEnemy attackingenemy;
void Awake ()
{
attackingenemy = GetComponentInChildren ();
SkelAttack = GetComponentInParent ();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == “Player” && foundplayer == false) {
playersoldier = other.gameObject;
playertransform = playersoldier.transform;
fighting = true;
foundplayer = true;
SphereCollider planetCollider = GetComponent ();
planetCollider.radius = .3f;
}
if (other.gameObject.tag == “Blocker”)
{
fighting = false;
}
}
void OnTriggerExit (Collider other)
{
if (other.gameObject.tag == “Blocker”)
{
foundplayer = false;
SphereCollider planetCollider = GetComponent ();
planetCollider.radius = 4f;
}
}
void Update ()
{
if (fighting == true && attackingenemy.alive == true)
{
transform.parent.LookAt (playertransform);
transform.parent.position += transform.parent.forward * runspeed * Time.deltaTime;
SkelAttack.running = true;
}
}
}
However I keep on getting an error “Object reference not set to an instance of an object” and the error message directs me to the line "if (fighting == true && attackingenemy.alive == true) ". Anyone know why this is happening and what I can do to fix it?