I have followed various tutorials trying to learn how to use lists. But the concept is still baffling me. below is the code to setup my list. i need to pull the last gameobject to use it as a target but cant figure it out.
using UnityEngine;
using System.Collections;
using System;
public class tailList : IComparable<tailList>
{
public GameObject titlePart;
public int power;
public tailList(GameObject newtitlePart, int newPower)
{
titlePart = newtitlePart;
power = newPower;
}
//This method is required by the IComparable
//interface.
public int CompareTo(tailList other)
{
if(other == null)
{
return 1;
}
//Return the difference in power.
return power - other.power;
}
}
`
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class curTail : MonoBehaviour {
public GameObject head;
// Use this for initialization
void Start () {
List<tailList> tailList = new List<tailList> ();
tailList.Add(new tailList(head,10));
}
}
public class joinTail : MonoBehaviour {
private Transform target;
private bool canMove = true;
void OnTriggerEnter(Collider other){
canMove = !canMove;
Debug.Log ("return check");
if (other.gameObject.name == "player"){
gameObject.AddComponent<FollowAI>();
Debug.Log (other);
//target = other.gameObject.transform;
//last item of list should replace "other".
FollowAI.targetHead = target;
}
}
}