Hey All,
So, in the GameController script I instantiate 1 posse leader and 10 members who I all give a posse value (int). In a script for posse members I want to check if the posseleader is still in the scene and if not, reset the posse-value of the members to 0.
This is my script:
using UnityEngine;
using System.Collections;
public class Posse : MonoBehaviour {
public int posse;
public GameController gameController;
public PosseLeader posseLeader;
// Use this for initialization
void Start ()
{
GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <GameController>();
}
if (gameControllerObject == null)
{
Debug.Log ("Cannot find GameController");
}
posse = gameController.posse;
}
// Update is called once per frame
void Update () {
var leader : GameObject[];
leader = GameObject.FindGameObjectsWithTag("enemy");
if (leader.length == 0) {
posse = 0;
}
if (leader.length != 0) {
for (int y=0; y <= leader.length; y++) {
GameObject posseLeaderObject = leader[y];
posseLeader = posseLeaderObject.GetComponent <PosseLeader>();
if (posseLeader.posse = posse){
posse = 0;
}
}
}
}
}
However, I get:
Assets/Scripts/Posse.cs(29,28): error CS1525: Unexpected symbol `:', expecting `)', `,', `;', `[', or `='
For the ‘:’ behind var leader. What am I doing wrong here? I took a snippet from: Unity - Scripting API: GameObject.FindGameObjectsWithTag
And, by any change, is the code after this correct / possible? Or should I tackle this problem differently?
Thanks in advance, it is just my first week in Unity so apologies for the level of my question.