Search Unity

Need help, paddle doesn't move when either side of screen is clicked

Discussion in 'Scripting' started by aali2018, May 14, 2020.

  1. aali2018

    aali2018

    Joined:
    May 14, 2020
    Posts:
    2
    been trying to get back into coding to give me a hobby/motivation during these times and I was following this tutorial on how to make a simple android game in unity in 2020 (
    )
    everything was going perfect until the 31-minute mark where he clicks the screen and the paddle moves to where he clicks but when I do it the paddle doesn't respond at all, I've watched the footage multiple times now and still can't see what I did wrong, can anyone help?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Paddle : MonoBehaviour
    6. {
    7.  
    8.     Rigidbody2D rb;
    9.     public float moveSpeed;
    10.  
    11.     private void Awake()
    12.     {
    13.         rb = GetComponent<Rigidbody2D>();
    14.     }
    15.  
    16.     // Start is called before the first frame update
    17.     void Start()
    18.     {
    19.  
    20.     }
    21.  
    22.     // Update is called once per frame
    23.     void Update()
    24.     {
    25.  
    26.     }
    27.  
    28.     private void Fixedupdate()
    29.     {
    30.         TouchMove();
    31.     }
    32.  
    33.     void TouchMove()
    34.     {
    35.  
    36.         if (Input.GetMouseButton(0))
    37.         {
    38.             Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    39.  
    40.             if (touchPos.x < 0)
    41.             {
    42.                 rb.velocity = Vector2.left * moveSpeed;
    43.  
    44.             }
    45.             else
    46.             {
    47.                 rb.velocity = Vector2.right * moveSpeed;
    48.  
    49.             }
    50.  
    51.         }
    52.         else
    53.         {
    54.             rb.velocity = Vector2.zero;
    55.         }
    56.    
    57.     }
    58.  
    59. }
    60.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Did you set your move speed to something > 0?
     
  3. aali2018

    aali2018

    Joined:
    May 14, 2020
    Posts:
    2
    Yup, set it to 8, is there like a way I can export my project so far so you guys can see?