Beispiel #1
0
    public void Shoot()
    {
        if (m_CurrentState == ShooterState.None && Input.GetButtonDown("Fire1"))
        {
            m_ForceSlider.value = 0.0f;
            m_ForceDirection    = 1;
            m_CurrentState      = ShooterState.Charging;
            StartCoroutine(ReleasesBall());
        }

        if (m_CurrentState == ShooterState.Charging && Input.GetButton("Fire1"))
        {
            m_ForceSlider.value   += (Time.deltaTime / m_TimeToMaxForce) * m_ForceDirection;
            m_ForceFillImage.color = Color.Lerp(m_MinForceColor, m_MaxForceColor, m_Curve.Evaluate(m_ForceSlider.value));
            if (m_ForceSlider.value >= 1.0f || m_ForceSlider.value <= 0.0f)
            {
                m_ForceDirection *= -1;
            }
        }

        if (m_CurrentState == ShooterState.Charging && Input.GetButtonUp("Fire1"))
        {
            Rb.mass = 0.1f;
            move    = true;
            FindObjectOfType <AudioManager>().play("ThrowBall");
            float force = m_ForceSlider.value * m_MaxForce;
            m_Rigidbody.AddForce(transform.forward * force);
            currentCamState = cameraState.side;
            m_CurrentState  = ShooterState.Moving;
            StartCoroutine(CheckStop());
        }
    }
Beispiel #2
0
 public void Start()
 {
     m_TimeToMaxForce = 2;       //Used to set the strength bar's speed at the start.
     Rb.mass          = 3000000; //Used to set the ball's mass at the start, avoiding it to move due to any collision
     m_CurrentState   = ShooterState.None;
     currentCamState  = cameraState.front;
     randomPosition();  // set the white ball's position at the start.
     changeWhiteBall(); // set the white ball's position at the start.
 }
Beispiel #3
0
    IEnumerator ReleasesBall()
    {
        yield return(new WaitForSeconds(6));

        if (move == false)
        {
            Rb.mass = 0.1f;
            FindObjectOfType <AudioManager>().play("ThrowBall");
            float force = m_ForceSlider.value * m_MaxForce;
            m_Rigidbody.AddForce(transform.forward * force);
            currentCamState = cameraState.side;
            m_CurrentState  = ShooterState.Moving;
            StartCoroutine(CheckStop());
        }
        move = false;
    }
Beispiel #4
0
    public IEnumerator CheckStop()
    {
        m_Arrow.SetPosition(0, transform.position);
        m_Arrow.SetPosition(1, transform.position);

        yield return(new WaitForSeconds(1.0f));

        while (m_Rigidbody.velocity.magnitude > 0.1f)
        {
            yield return(new WaitForEndOfFrame());
        }

        m_Rigidbody.velocity = Vector3.zero;
        transform.rotation   = Quaternion.Euler(-Vector3.right);
        currentCamState      = cameraState.front;
        m_CurrentState       = ShooterState.ok;
        m_Shoot  = true;
        this.tag = "OffBlueBall";
        StartCoroutine(FeedBack.DestroyFeedBack());
    }
Beispiel #5
0
 void ChangeCameraState(cameraState newCameraState)
 {
     currentCameraState = newCameraState;
 }