예제 #1
0
    void Update()
    {
        if (target == null || target.IsDestoyed())
        {
            GetRepairableTarget();
        }

        if (!destroying && target != null && !target.IsDestoyed())
        {
            float direction = target.transform.position.x - transform.position.x;

            Vector3 directionVector = new Vector3(direction, 0, 0);
            directionVector.Normalize();

            transform.Translate(directionVector * speed * Time.deltaTime);

            enemyWalkAnimator.SetBool("Walking", true);
            if (directionVector.x > 0)
            {
                transform.localScale = new Vector3(-1, 1, 1);
            }
            else if (directionVector.x < 0)
            {
                transform.localScale = new Vector3(1, 1, 1);
            }
        }

        if (destroying && target != null)
        {
            if (!target.IsDestoyed())
            {
                accAttackTime += Time.deltaTime;

                if (accAttackTime >= attackTime)
                {
                    accAttackTime = 0.0f;
                    target.TakeDamage();
                }
            }

            if (target.IsDestoyed())
            {
                destroying = false;
            }

            enemyWalkAnimator.SetBool("Walking", false);
        }

        if (destroying)
        {
            enemyActionAnimator.SetTrigger("Attack");
        }
    }
예제 #2
0
    public ShipState GetShipState()
    {
        ShipState shipState;

        shipState.repairableObjectCount          = 0;
        shipState.repairableObjectDestroyedCount = 0;
        shipState.repairableObjectMidLifeCount   = 0;
        shipState.repairableObjectFullLifeCount  = 0;

        for (int i = 0; i < objectsList.list.Count; i++)
        {
            shipState.repairableObjectCount++;
            RepairableObject repairableObject = objectsList.list[i];
            if (repairableObject.IsDestoyed())
            {
                ++shipState.repairableObjectDestroyedCount;
            }
            else if (repairableObject.IsAtFullHealth())
            {
                ++shipState.repairableObjectFullLifeCount;
            }
            else
            {
                ++shipState.repairableObjectMidLifeCount;
            }
        }
        return(shipState);
    }