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

I need Help with Pong Like Game For Android

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

  1. bracciata

    bracciata

    Joined:
    Apr 1, 2015
    Posts:
    8
    using UnityEngine;
    using System.Collections;
    public class MoveRacket : MonoBehaviour {
    public float speed = 30;
    public string axis = "Vertical";

    void FixedUpdate () {
    float v = Input.GetAxisRaw (axis);
    GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, v) * speed;
    if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved) {
    // Get movement of the finger since last frame
    var touchDeltaPosition = Input.GetTouch (0).deltaPosition;
    // Move object across XY plane
    transform.Translate (-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0);

    }
    }
    }

    That is currently my code the touch input part was just copied and pasted and it sort of works but I only want Y to change position and maybe I could have to drag it up. As of now when I click my racket just disappears .Thanks for the help in advance, I am an absolute beginner.
     
  2. Banderillo

    Banderillo

    Joined:
    May 12, 2015
    Posts:
    2
    Hello. Before all, sorry for my bad english.

    I'm completely new to Unity, and i have no idea of inputs on mobiles. I'm doing a pong game too, and have copied your code for inputs in mobiles. Simply i have change the speed to 0.40 and in transform.Translate i have put 0 in x parameter and it works.

    I suppose that you have solucionated the problem, but maybe this can help to solutionate this, to anybody that have the same problem. (I used Unity 5).
     

    Attached Files: