コード例 #1
0
    // Start is called before the first frame update

    /*
     *
     * In this function I set the 3 input fields that we have to zero
     */

    void Start()
    {
        // audioData = GetComponent<AudioSource>();
        // audioData.Play(0);
        m_rb = GetComponent <Rigidbody>();
        Assert.IsNotNull(m_rb, "Houston, we've got a problem here! No Rigidbody attached");
        Xpos.GetComponent <UnityEngine.UI.InputField>().text = "0";
        Ypos.GetComponent <UnityEngine.UI.InputField>().text = "0";
        Zpos.GetComponent <UnityEngine.UI.InputField>().text = "0";
        CreateTargetDisplay();
    }
コード例 #2
0
    // Update is called once per frame

    /*
     * By uncommenting the movePlayer function, you can move the player but since it is penalty kick game,
     * I thought it is better to comment this.
     *
     * next i Check the target position, if it is equal to (0,0,0), it means that the player has not set the target
     * or the user has restarted the game. So I set the velocity of ball to zero cause I don't want it to move.
     * */
    void Update()
    {
        // movePlayer();
        updateTargetPos();

        if (m_TargetDisplay != null && m_bIsGrounded)
        {
            if (m_vTargetPos.y == 0 && m_vTargetPos.z == 0 && m_vTargetPos.x == 0)
            {
                m_TargetDisplay.transform.position = Vector3.zero;
                m_vInitialVel = Vector3.zero;
                m_rb.velocity = m_vInitialVel;
                vDebugHeading = Vector3.zero;
            }
            //If the ball is not in the goal position,  I still calculate the heading and target display position
            else
            {
                if (!goal)
                {
                    m_TargetDisplay.transform.position = m_vTargetPos;

                    vDebugHeading = m_vTargetPos - transform.position;
                }
            }
        }
        //If the user presses shoot, he can kick the ball
        if (m_bDebugKickBall && m_bIsGrounded)
        {
            m_bDebugKickBall = false;
            addScore         = false;
            OnKickBall();
        }
        //If the user restart the game, every variable restarts as well except the score
        if (m_bRestart)
        {
            m_vTargetPos = Vector3.zero;
            m_TargetDisplay.transform.position = m_vTargetPos;
            transform.position = initialPos;
            goal          = false;
            addScore      = false;
            m_rb.position = initialPos;
            Xpos.GetComponent <UnityEngine.UI.InputField>().text = "0";
            Ypos.GetComponent <UnityEngine.UI.InputField>().text = "0";
            Zpos.GetComponent <UnityEngine.UI.InputField>().text = "0";
            m_bRestart = false;
        }
        //Check to see if the ball is whithin the goal post
        checkBound();
        //If the ball is in the goal, I multiply the velocity in the y axis casue I want the ball to fall there.
        //I also add to the score
        if (goal)
        {
            if (!addScore)
            {
                goalCount++;
            }
            addScore        = true;
            m_vInitialVel.z = 0.0f;
            if (m_vInitialVel.y > 0.0f)
            {
                m_vInitialVel.y = -1 * m_vInitialVel.y;
            }
            m_rb.velocity = m_vInitialVel;
            goal          = false;
        }
    }
コード例 #3
0
 //In this function, I update the target position by the inputs I received from the player
 private void updateTargetPos()
 {
     m_vTargetPos.x = float.Parse(Xpos.GetComponent <UnityEngine.UI.InputField>().text);
     m_vTargetPos.y = float.Parse(Ypos.GetComponent <UnityEngine.UI.InputField>().text);
     m_vTargetPos.z = float.Parse(Zpos.GetComponent <UnityEngine.UI.InputField>().text);
 }