Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //as long as the aim isn't null & the ball is grounded....
        if (m_AimDisplay != null && m_bIsGrounded)
        {
            //...set the red line from the ball's position to the target's position
            vDebugHeading = m_AimDisplay.getPosition() - transform.position;
        }

        //if the scene is on Level 1 or 2, set the ground level on 0.5f unit (on the grass)
        if (scene.name == "Level1" || scene.name == "Level2")
        {
            setGroundLevel(0.5f);
        }
        //if the scene is on Level 3, set the ground level on 1.3f unit (on a pedastal)
        else if (scene.name == "Level3")
        {
            setGroundLevel(1.3f);
        }

        //if the ball is in the net (close the user POV)....
        if (transform.position.z < -2.0f)
        {
            //.. the player can move the target...
            m_AimDisplay.moveTarget();
            //.. and shoot the ball with Key 'SPACEBAR' as long as the ball is on the ground
            if (Input.GetKeyDown(KeyCode.Space) && m_bIsGrounded == true)
            {
                OnKickBall();
            }
        }

        //if the ball is not close to the net & the ball is grounded....
        if (Input.GetKeyDown(KeyCode.R) && (transform.position.z > 5.0f || m_bIsGrounded == true))
        {
            //...player is able to reset the ball's position (using Reset method)
            Reset();
        }

        //always update the ball's x position (X Axis) based on the aim's x position
        transform.position = new Vector3(m_AimDisplay.getPosition().x, transform.position.y, transform.position.z);
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        //create the game object for the UI (to get the score / # of targets left)
        targetsLeft = GameObject.FindGameObjectWithTag("Score").GetComponent <TargetsLeftUI>();
        //create the scene object to get the active/current scene
        scene = SceneManager.GetActiveScene();

        //creates the game object for the aim
        m_AimDisplay = GameObject.FindGameObjectWithTag("Aim").GetComponent <AimBehavior>();

        //sets the variable for the ball's rigidbody
        m_rb = GetComponent <Rigidbody>();
        Assert.IsNotNull(m_rb, "Houston, we've got a problem here! No Rigidbody attached");

        //sets the aim original position to whatever position the aim is currently in (from the editor)
        m_vAimOriginalPos = m_AimDisplay.getPosition();

        //sets the ball original position to whatever position the ball is currently in (from the editor)
        m_vOriginalPos = transform.position;
    }