コード例 #1
0
 void Awake()
 {
     rb       = GetComponent <Rigidbody2D>();
     follower = GetComponent <Follower2D>();
     audioSrc = GetComponent <AudioSource>();
     paddle   = GameObject.FindWithTag("Paddle");
 }
コード例 #2
0
    void Update()
    {
        if (!inMenu)
        {
            Follower2D follower = paddle.GetComponent <Follower2D>();

            if (Input.GetAxis("Horizontal") != 0)
            {
                if (follower.enabled)
                {
                    follower.enabled = false;
                }

                Debug.Log("[Input] Horizontal");
                Vector3 newPos = paddle.transform.position;
                newPos += new Vector3(Input.GetAxis("Horizontal"), 0, 0);

                paddle.SendMessage("OnMove", newPos, SendMessageOptions.DontRequireReceiver);
            }

            if (Input.GetButtonDown("Fire1"))
            {
                Ball ball = GameObject.FindWithTag("Ball") ? GameObject.FindWithTag("Ball").GetComponent <Ball>() : null;

                if (!follower.enabled)
                {
                    follower.enabled = true;
                }
                else if (ball != null && !ball.launched)
                {
                    ball.Launch();
                }
            }

            if (Input.GetButtonDown("Submit"))
            {
                Ball ball = GameObject.FindWithTag("Ball") ? GameObject.FindWithTag("Ball").GetComponent <Ball>() : null;

                if (ball != null && !ball.launched)
                {
                    ball.Launch();
                }
            }
        }
    }