Question by
James_Sterling · Sep 27, 2016 at 03:14 PM ·
movement2d game2d-gameplay
I want to click/touch and move my object(2D) on Y axis at certain speed, and I want it so if the user clicks again the speed will not change until it touches a certain object(Line).
I want to click/touch and move my object(2D) on Y axis at certain speed, and I want it so if the user clicks again the speed will not change until it touches a certain object(Line).
Comment
Answer by James_Sterling · Sep 27, 2016 at 04:46 PM
Basically figured it out!
using UnityEngine; using System.Collections;
public class GameBallMove : MonoBehaviour {
public float BallMoveForce = 10f;
private Rigidbody2D rb;
private bool ballInPlay;
// Use this for initialization
void Awake () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonUp(0) && ballInPlay == false)
{
ballInPlay = true;
rb.AddForce(new Vector2(0, BallMoveForce));
}
}
}