Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (crab.dood)
     {
         timer += Time.deltaTime;
         if (timer > reviveTime)
         {
             crab.OnRevive();
         }
     }
     else
     {
         timer = 0;
     }
 }
Example #2
0
    private void Update()
    {
        if (dood)
        {
            return;
        }

        gamePadState = GamePad.GetState(playerIndex);
        if (gamePadState.IsConnected)
        {
            GetInputs();
            Move(leftStickInput);
        }

        //Check if in shell and button pressed
        if (nearestShell != null)
        {
            if (gamePadState.Triggers.Left > triggerTreshold)
            {
                if (!IsInShell)
                {
                    if (nearestShell.AttachCrab(this))
                    {
                        IsInShell = true;
                    }
                }
            }
            else
            {
                IsInShell = false;
                nearestShell.DetachCrab(this);
            }
        }
        else
        {
            IsInShell = false;
            if (nearestShell != null)
            {
                nearestShell.DetachCrab(this);
            }
        }

        if (IsInShell)
        {
            //SpotLight rotation;
            if (rightStickInput != Vector2.zero)
            {
                nearestShell.shell.SpotLightHolder.transform.rotation =
                    Quaternion.RotateTowards(
                        nearestShell.shell.SpotLightHolder.transform.rotation,
                        Quaternion.Euler(0, Mathf.Atan2(-rightStickInput.y, rightStickInput.x) * Mathf.Rad2Deg + 90, 0), 180f * Time.deltaTime);
            }

            //Add pickup to the shell
            if (pickedUpItem != null)
            {
                pickedUpItem.transform.SetParent(null);
                pickedUpItem.OnAttachToShell();
                nearestShell.shell.AttachPickup(pickedUpItem);
                pickedUpItem = null;
            }
            rigidbody.position = Vector3.Scale(nearestShell.transform.position, new Vector3(1, 0, 1));
        }
        else
        {
            if (nearestPickup != null && pickedUpItem == null)
            {
                if (gamePadState.Triggers.Right > triggerTreshold)
                {
                    pickedUpItem = nearestPickup;
                    pickedUpItem.OnPickup(transform);
                    AudioManager.Instance.PlayAudio(transform.position, "Pickup", is3D: false);
                }
            }
            if (pickedUpItem != null && gamePadState.Triggers.Right < triggerTreshold)
            {
                pickedUpItem.OnRelease();
                pickedUpItem = null;
            }
        }

        if (nearestCrab != null && nearestCrab.dood)
        {
            if (gamePadState.Triggers.Right > triggerTreshold)
            {
                nearestCrab.OnRevive();
            }
        }
    }