Esempio n. 1
0
    void DetectShoot()
    {
        switch (gameObject.name)
        {
        case ("Player1"):
            if (Input.GetKeyDown(KeyCode.D) && hurted == 0)
            {
                Slot.Types?type = NoteSelector.GetComponent <NoteSelector>().useSelectedType();
                if (type != null)
                {
                    SpawnNote(1, noteSpeed, (Slot.Types)type);
                    if (OnThrow != null)
                    {
                        OnThrow.Invoke();
                    }
                }
            }
            break;

        case ("Player2"):
            if (Input.GetKeyDown(KeyCode.LeftArrow) && hurted == 0)
            {
                Slot.Types?type = NoteSelector.GetComponent <NoteSelector>().useSelectedType();
                if (type != null)
                {
                    SpawnNote(2, noteSpeed, (Slot.Types)type);
                    if (OnThrow != null)
                    {
                        OnThrow.Invoke();
                    }
                }
            }
            break;
        }
    }
Esempio n. 2
0
    // This is an unsafe function! Must check length of currentThrowables before calling it (like in HandleThrowInput() above)!
    private void ThrowNext()
    {
        GameObject current = currentThrowables[0];
        currentThrowables.RemoveAt(0);

        Rigidbody currentRigidbody = current.GetComponent<Rigidbody>();
        if (currentRigidbody)
        {
            // Display the object, center at the throw point, remove parent, then throw in the same path of the current launch arc
            // - the force angle is partly from just testing and playing with the values
            current.SetActive(true);
            current.transform.localPosition = Vector3.zero;
            current.transform.parent = null;
            currentRigidbody.AddForce(Quaternion.AngleAxis((launchArcRenderer.angle % 180f) - 90, launchArcRenderer.transform.forward) * launchArcRenderer.transform.up * (launchArcRenderer.velocity * throwMultiplier), ForceMode.Impulse);
        }

        // Disable/hide the launchArcRenderer after throwing
        launchArcRenderer.gameObject.SetActive(false);

        OnThrow?.Invoke(current.GetComponent<Interactable>());

        StartCoroutine(FadeOutAndDelete(current, throwableDestroyTime));
    }
Esempio n. 3
0
 public void Throw()
 {
     OnThrow?.Invoke();
 }
Esempio n. 4
0
 private void ThrowBall()
 {
     OnThrow?.Invoke();
     animator.SetTrigger(ThrowTrigger);
 }