Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Change code in game like pong from computer to touch

Discussion in 'Scripting' started by bracciata, Apr 2, 2015.

  1. bracciata

    bracciata

    Joined:
    Apr 1, 2015
    Posts:
    8
    Below is my current code and I want to change it so I can either drag the racket or where I touch the racket goes. Thanks ahead of time I am an absolute beginner.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MoveRacket : MonoBehaviour {
    5.         public float speed = 30;
    6.         public string axis = "Vertical";
    7.  
    8.         void FixedUpdate () {
    9.         float v = Input.GetAxisRaw (axis);
    10.           GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v) * speed;
    11.  
    12.  
    13.  
    14.     }
    15. }
     
    Last edited: Apr 3, 2015
  2. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
  3. bracciata

    bracciata

    Joined:
    Apr 1, 2015
    Posts:
    8