The primary target is the player, the secondary target for the attacker is always equal to the current follower. But what if there is no current follower? Currently it says “Object reference not set to the instance of an object”
private Follower SecondaryFollower;
SecondaryTarget = GetComponent ().CurrentFollower;
My script:
using UnityEngine;
using System.Collections;
public class OneFollower : MonoBehaviour {
public Follower HumanFollowerGet;
public Follower AlienFollowerGet;
public Follower CurrentFollower;
void Start () {
HumanFollowerGet = GameObject.Find ("Human Follower").GetComponent <Follower> ();
AlienFollowerGet = GameObject.Find ("Alien Follower").GetComponent <Follower> ();
}
void Update () {
Debug.Log (CurrentFollower);
if (HumanFollowerGet.Following == true)
{
ChangeFollower (HumanFollowerGet);
}
if (AlienFollowerGet.Following == true)
{
ChangeFollower (AlienFollowerGet);
}
}
void ChangeFollower (Follower NewFollower) {
if (CurrentFollower)
{
CurrentFollower.Following = false;
}
CurrentFollower = NewFollower;
CurrentFollower.Following = true;
}
}