Пример #1
0
 void checkRolling()
 {
     if (playerBallRB.IsSleeping())
     {
         StrokeMode = StrokeModeEnum.AIMING;
     }
 }
Пример #2
0
    // Update is called once per visual frame -- use this for inputs
    private void Update()
    {
        if (StrokeMode == StrokeModeEnum.AIMING)
        {
            StrokeAngle += Input.GetAxis("Horizontal") * 100f * Time.deltaTime;

            if (Input.GetButtonUp("Fire"))
            {
                StrokeMode = StrokeModeEnum.FILLING;
                return;
            }
        }

        if (StrokeMode == StrokeModeEnum.FILLING)
        {
            StrokeForce += (strokeForceFillSpeed * fillDir) * Time.deltaTime;
            if (StrokeForce > MaxStrokeForce)
            {
                StrokeForce = MaxStrokeForce;
                fillDir     = -1;
            }
            else if (StrokeForce < 0)
            {
                StrokeForce = 0;
                fillDir     = 1;
            }

            if (Input.GetButtonUp("Fire"))
            {
                StrokeMode = StrokeModeEnum.DO_WHACK;
            }
        }
    }
Пример #3
0
    // FixedUpdate runs on every tick of the physics engine, use this for manipulation
    void FixedUpdate()
    {
        if (playerBallRB == null)
        {
            // Might not be an error -- maybe the ball fell out of bounds, got deleted,
            // and hasn't respawned yet.
            return;
        }

        if (StrokeMode == StrokeModeEnum.BALL_IS_ROLLING)
        {
            CheckRollingStatus();
            return;
        }

        if (StrokeMode != StrokeModeEnum.DO_WHACK)
        {
            return;
        }

        // Whackadaball

        Debug.Log("Whacking it!");

        Vector3 forceVec = new Vector3(0, 0, StrokeForce);

        playerBallRB.AddForce(Quaternion.Euler(0, StrokeAngle, 0) * forceVec, ForceMode.Impulse);

        StrokeForce = 0;
        fillDir     = 1;
        StrokeCount++;

        StrokeMode = StrokeModeEnum.BALL_IS_ROLLING;
    }
Пример #4
0
 // Start is called before the first frame update
 void Start()
 {
     playerBallRB    = ball.GetComponent <Rigidbody>();
     audioSource     = ball.GetComponent <AudioSource>();
     StrokeMode      = StrokeModeEnum.AIMING;
     StrokeCount     = 0;
     StrokeText.text = "Strokes: " + StrokeCount.ToString();
 }
 void CheckRollStatus()
 {
     // Is the ball roll ?
     if (playerBallRB.IsSleeping())
     {
         StrokeMode = StrokeModeEnum.AIMING;
     }
 }
    // Update is called once per visual frame Input

    private void Update()
    {
        if (StrokeMode == StrokeModeEnum.AIMING)
        {
            StrokeAngle += Input.GetAxis("Horizontal") * 100f * Time.deltaTime;
            if (Input.GetButtonUp("Fire"))
            {
                StrokeMode = StrokeModeEnum.FILL_UP;
                return;
            }
        }

        if (StrokeMode == StrokeModeEnum.FILL_UP)
        {
            StrokeForce += (StrokeForceFillSpeed * fillDir) * Time.deltaTime;
            if (StrokeForce > MaxStrokeForce)
            {
                StrokeForce = MaxStrokeForce;
                fillDir     = -1;
            }
            else if (StrokeForce < 0)
            {
                StrokeForce = 0;
                fillDir     = 1;
            }


            if (Input.GetButton("Cancel"))
            {
                StrokeMode  = StrokeModeEnum.AIMING;
                StrokeForce = 0;
                return;
            }


            if (Input.GetButtonUp("Fire"))
            {
                StrokeMode = StrokeModeEnum.READY_SHOOT;
                audioSource.PlayOneShot(clip, volume);
            }
        }

        if (Input.GetButtonUp("Quit"))
        {
            SceneManager.LoadScene(0);
        }
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        StrokeText.text = "Strokes: " + StrokeCount.ToString();
        if (StrokeMode == StrokeModeEnum.AIMING)
        {
            arrow.gameObject.SetActive(true);
            //change putt angle
            StrokeAngle += Input.GetAxis("Horizontal") * 100f * Time.deltaTime;

            //switch to powering up
            if (Input.GetButtonUp("Fire1"))
            {
                StrokeMode = StrokeModeEnum.POWERING;
                return;
            }
        }

        if (StrokeMode == StrokeModeEnum.POWERING)
        {
            //power meter fills up and back down
            StrokePower += (fillTime * fill) * Time.deltaTime;
            if (StrokePower > maxPower)
            {
                StrokePower = maxPower;
                fill        = -1;
            }
            else if (StrokePower < 0)
            {
                StrokePower = 0;
                fill        = 1;
            }
            //if hits button, shoot
            if (Input.GetButtonUp("Fire1"))
            {
                StrokeMode = StrokeModeEnum.PUTT;
            }
        }
    }
Пример #8
0
    void FixedUpdate()
    {
        if (StrokeMode == StrokeModeEnum.ROLLING)
        {
            checkRolling();
            return;
        }
        else if (StrokeMode != StrokeModeEnum.PUTT)
        {
            return;
        }
        //Putt
        arrow.gameObject.SetActive(false);
        StrokeCount++;

        StrokeMode = StrokeModeEnum.ROLLING;
        audioSource.Play();
        Vector3 forceVec = new Vector3(0, 0, StrokePower);

        playerBallRB.AddForce(Quaternion.Euler(0, StrokeAngle, 0) * forceVec, ForceMode.Impulse);
        StrokePower = 0;
        fill        = 1;
    }
    // FixedUpdate runs on every tick of the physics engine, Manipulation
    void FixedUpdate()
    {
        if (StrokeMode == StrokeModeEnum.BALL_ROLLING)
        {
            CheckRollStatus();
            return;
        }

        if (StrokeMode != StrokeModeEnum.READY_SHOOT)
        {
            return;
        }

        // Ball roll

        Vector3 forceVec = new Vector3(StrokeForce, 0, 0);

        playerBallRB.AddForce(Quaternion.Euler(0, StrokeAngle, 0) * forceVec, ForceMode.Impulse);

        StrokeForce = 0f;
        fillDir     = 1;
        StrokeCount++;
        StrokeMode = StrokeModeEnum.BALL_ROLLING;
    }