コード例 #1
0
    private bool isPatrollingBackwards = false; //flips when bot reaches end of patrol path and heads back

    // Use this for initialization
    void Start()
    {
        transform.position    = patrol.path[0].transform.position;
        destination           = patrol.path[1];
        playerFollowCountDown = playerFollowTime;
        lastKnownPosition     = Vector3.zero;
    }
コード例 #2
0
 // Use this for initialization
 void Start()
 {
     transform.position    = patrol.path[0].transform.position;
     destination           = patrol.path[1];
     spotlight             = GetComponent <Collider2D>();
     playerFollowCountDown = playerFollowTime;
     lastKnownPosition     = Vector3.zero;
 }
コード例 #3
0
    //check destination, swap if necessary
    void checkDestinationAgainstPatrol()
    {
        //TODO: make this clean
        if ((transform.position - destination.transform.position).magnitude <= 0.1f)
        {
            //reached destination node, set next one
            if (!isPatrollingBackwards)                       //moving forwards through path
            {
                if (destinationIndex + 1 < patrol.path.Count) //there are more nodes ahead
                {
                    PatrolPathNode nextNode = patrol.path[destinationIndex + 1];
                    destination = nextNode;
                    destinationIndex++;
                }
                else                   //no more nodes in this direction, start moving the other way
                {
                    isPatrollingBackwards = true;
                    if (destinationIndex - 1 >= 0)                       //there are nodes behind this one
                    {
                        PatrolPathNode nextNode = patrol.path[destinationIndex - 1];
                        destination = nextNode;
                        destinationIndex--;
                        gameObject.GetComponent <SpriteRenderer>().flipX ^= true;                        //bitwise OR--flips value
                    }
//					else { //only one node in this patrol
//						//stay where we are (this isn't desired and will probably break,
//						//but i'm not testing this because deadlines)
//					}
                }
            }
            else               //moving backwards through path -- same logic as above but reversed
            {
                if (destinationIndex - 1 >= 0)
                {
                    PatrolPathNode nextNode = patrol.path[destinationIndex - 1];
                    destination = nextNode;
                    destinationIndex--;
                }
                else
                {
                    isPatrollingBackwards = false;
                    if (destinationIndex + 1 < patrol.path.Count)
                    {
                        PatrolPathNode nextNode = patrol.path[destinationIndex + 1];
                        destination = nextNode;
                        destinationIndex++;
                        gameObject.GetComponent <SpriteRenderer>().flipX ^= true;                        //bitwise OR--flips value
                    }
                }
            }
        }
    }
コード例 #4
0
 void OnEnable()
 {
     // try to get path nodes in the child objects
     nodePath.Clear();
     path.Clear();
     foreach (Transform child in transform)
     {
         PatrolPathNode pn = child.GetComponent <PatrolPathNode> ();
         if (pn)
         {
             nodePath.Add(pn);
             path.Add(child.position);
         }
     }
 }
コード例 #5
0
 public bool Equals(PatrolPathNode other)
 {
     return(this.GetInstanceID() == other.GetInstanceID());
 }