Beispiel #1
0
    //Every time a unit dies, check if there are any ghosts or pets left
    public void checkForUnits(object obj)
    {
        void Check()
        {
            Ghost[] ghosts = FindObjectsOfType <Ghost>();
            Pet[]   pets   = FindObjectsOfType <Pet>();

            Debug.Log("ghost array:" + ghosts.Length);
            Debug.Log("pet array:" + pets.Length);

            if (ghosts.Length - 1 < 0)
            {
                EventManager.TriggerEvent(GameEvent.levelFinished);
                EventManager.TriggerEvent(GameEvent.playerWon);
                Debug.Log("player won triggered, level finsihed trigger");
            }
            else if (pets.Length - 1 < 0)
            {
                EventManager.TriggerEvent(GameEvent.levelFinished);
                EventManager.TriggerEvent(GameEvent.playerLost);
                Debug.Log("player lost triggered, level finish triggered");
            }
        }

        PetUtility.WaitAndDo(0.03f, Check); //because the unit is destroied later
    }
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        if (fish.launchingAttack)
        {
            //checking hit
            RaycastHit2D hit2D;
            //if hit a wall, change direction
            hit2D = Cast("Wall");
            if (hit2D)
            {
                direction = -direction;
                PetUtility.FlipTransform(fish.transform);
                passedEnemies.Clear();
            }

            //if hit an enemy, attack enemy
            hit2D = Cast("Ghost");
            if (hit2D)
            {
                Ghost ghost = hit2D.collider.GetComponent <Ghost>();
                if (!passedEnemies.Contains(ghost))
                {
                    ghost.TakeDamage(fish.damage);
                    passedEnemies.Add(ghost);
                }
            }

            //if comeback to origin position, stop launching attack and set the timer for next attack
            if (Mathf.Abs(fish.transform.position.x - start.x) <= fish.rollingSpeed / 29 && (PetUtility.GetSameFloorGhost(fish.transform.position) == null) && rolling)
            {
                fish.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
                //Debug.Log("Back To Start!");
                rolling = false;
                void FinishAttack()
                {
                    fish.launchingAttack = false;
                    stopTime             = Time.time;
                }

                PetUtility.WaitAndDo(fish.rollingGap, FinishAttack);
                return;
            }
            else if (rolling)
            {
                //setting velocity
                Vector2 velocity = fish.GetComponent <Rigidbody2D>().velocity;
                velocity.x = fish.rollingSpeed * direction;
                fish.GetComponent <Rigidbody2D>().velocity = velocity;
            }
        }
        else if (Time.time - fish.rollingGap >= stopTime)
        {
            //start Rolling
            fish.launchingAttack = true;
            rolling = true;
            Init(animator);
        }
    }
Beispiel #3
0
    private void Exit()
    {
        void startWalking()
        {
            unit.enterDoor = false;
        }

        PetUtility.Coroutine(PetUtility.LinearZoom(Vector3.zero, originScale, exitTime, gameObject.transform));
        PetUtility.WaitAndDo(exitTime, startWalking);
    }
Beispiel #4
0
 void Release()
 {
     selected = false;
     if (iAmPet && TryFindOffer())
     {
         ActiveUnit();
         Destroy(gameObject);
         PetUtility.WaitAndDo(0.1f, scroller.RerangeCards);
     }
     //put down the pet once its released
 }
Beispiel #5
0
    private void Enter()
    {
        //Debug.Log("enter door");
        //you want play the animation, wait, teleport and change state
        if (!entering)
        {
            entering = true;
            void exitDoor()
            {
                gameObject.transform.position = door.OtherEndPos();
                entering = false;
                Exit();
            }

            PetUtility.Coroutine
                (PetUtility.LinearZoom(originScale, Vector3.zero, enterTime, gameObject.transform));
            PetUtility.WaitAndDo(enterTime, exitDoor);
        }
    }
Beispiel #6
0
    public virtual void TakeDamage(float damage)
    {
        float changeColorTime = 0.08f;

        foreach (SpriteRenderer r in gameObject.GetComponentsInChildren <SpriteRenderer>())
        {
            if (r.gameObject.layer == 1)
            {
                continue;
            }
            r.color = Color.red;
        }

        lastDamageTime = Time.time;
        void restoreColor()
        {
            if (renderer != null && Time.time - lastDamageTime > changeColorTime)
            {
                foreach (SpriteRenderer r in gameObject.GetComponentsInChildren <SpriteRenderer>())
                {
                    if (r.gameObject.layer == 1)
                    {
                        continue;                          //layer 1 is transparentFX, should be ignored
                    }
                    r.color = originColors[r];
                }
            }
        }

        PetUtility.WaitAndDo(changeColorTime, restoreColor);
        health -= damage;
        EventManager.TriggerEvent(ParameterizedGameEvent.unitHealthChange, this);
        if (health <= 0)
        {
            Kill();
        }
    }
Beispiel #7
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     unit = animator.GetComponent <UnitBehaviour>();
     PetUtility.WaitAndDo(waitTime, unit.enemy.GetComponent <Ghost>().Kill);
     unit.enemy = null;
 }