示例#1
0
 void Start()
 {
     status = 0;
     myCID  = CreatureId + 1;
     CreatureId++;
     Creatures[myCID] = gameObject;
     _health          = gameObject.GetComponent <HealthHandler>();
     _method          = DeathMethod;
     _health.RegisterDeathMethod(_method);
     _pathAI          = gameObject.GetComponent <AIPath>();
     killObject       = CastleDefend.GetStructure(gameObject);
     body             = gameObject.GetComponent <Rigidbody2D>();
     _seeker          = gameObject.GetComponent <Seeker>();
     scanIndex        = Structures.currentScan;
     _aiPath          = gameObject.GetComponent <AIPath>();
     direction        = 0;
     _animator        = gameObject.GetComponent <Animator>();
     _pathAI.maxSpeed = Random.Range(MinSpeed, MaxSpeed);
     _seeker.StartPath(transform.position, killObject.transform.position, OnPathComplete);
 }
示例#2
0
    public static CastleDefend GetStructure(GameObject caller)
    {
        CastleDefend result = null;

        foreach (CastleDefend d in _defend)
        {
            if (result == null)
            {
                result = d;
            }
            else
            {
                var magA = (caller.transform.position - d.transform.position).magnitude;
                var magB = (caller.transform.position - result.transform.position).magnitude;
                if (magA < magB)
                {
                    result = d;
                }
            }
        }
        return(result);
    }