- Home /
A simple 2D pong game doesn't run
So Hi, fairly new to the Unity.I was watching a tutorial on how to make a small 2D game called Pong, its really simple.I created the objects and even wrote the C# program properly. the program is basically just to move my paddle up and down using UnityEngine; using System.Collections;
public class paddle : MonoBehaviour {
public float paddlespeed = 1;
public Vector3 playerPos;
void Update ()
{
float yPos = gameObject.transform.position.y + (Input.GetAxis ("Vertical") * paddlespeed);
playerPos = new Vector3 (-20, Mathf.Clamp(yPos,-11,11),0);
gameObject.transform.position = playerPos;
}
} but when I run the game,it doesn't do anything.What am I missing ?
This script will instantly move the paddle, regardless of the paddle speed. You should try tinkering around with Transform.Translate, very useful for moving objects!
Answer by slimsami · Jul 06, 2015 at 06:19 PM
Have you attached the script to a gameobject in the scene? after doing that you should also define in the editor the playerPos.
Both actions can be made by drag and drop, by dragging the script to an object in the scene and dragging your playerPos to the property showed in the editor
Your answer
Follow this Question
Related Questions
loading large scale creo file. 0 Answers
Where to start (with mixed experience)? 1 Answer
Getting Started, know my goal but what's a good first-game for me to Create? 2 Answers
Making my first game? 3 Answers