- Home /
Moving objects via Mouse and Touch on Y axis
I want to make an object move on only the Y-axis only, moving to a mouse click or touch. I want to make several objects do this so I how do i make each one separately move up and down and not at the same time when pressed above or below them. Sorry Im new at this :P
Answer by See_Sharp · Mar 15, 2016 at 08:54 AM
Break your question down, and hit google. If there's something you're stuck with, hit google again. This is the basics of basics, and google has a zillion hits on all of these problems you might encounter.
Here's a break down to feed your google:
"Unity how to move a gameobject"
"Unity move object along one axis"
"Unity move gameobject to mouse position"
"Unity get closest object"
Answering this with a complete script feels like working for free, and you haven't learned a thing out of it.
Thanks so much ^.^ Was needing a lil push in the correct direction. I now have it move up and down, but it moves too slowly: using UnityEngine; using System.Collections;
public class NewBehaviourScript : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 mouse = Input.mousePosition;
mouse = mouse;
transform.position = new Vector3(0, Camera.main.ScreenToViewportPoint(mouse).y, 0);
}
}
mouse = mouse ? <- this line of code doesn't do anything. Also, you'll need ScreenToWorldPos
, not ScreenToViewportPoint
.
Your answer
Follow this Question
Related Questions
Object spawned during collision: Object's Y axis to be colliding object's polygon's direction 1 Answer
first person controller parent move objects along y-axis 1 Answer
Shooting an object through a tube of cannon in a projectile manner. 0 Answers
How do I Adjust The Colour Of My Object By Percentages? 1 Answer
Object from flash to unity 2 Answers