Quantcast
Channel: Questions in topic: "moveto"
Viewing all articles
Browse latest Browse all 116

Convert Mouse Position to move a cube on 1-axis.

$
0
0
Hello! This is my post here, and first of all i must say that i'm really at a starting point on C# scripting and Unity.. What i want to do it, using iTween Plugin, move a cube on y-axis at the same screen height of mouse click. The error i'm getting is > NullReferenceException UnityEngine.Camera.WorldToScreenPoint (Vector3 position) Cube.Update () (at Assets/Cube.cs:17) The code i'm using, attached to Cube object, is: using UnityEngine; using System.Collections; public class Cube : MonoBehaviour { private Vector3 mousePos; void Start () { } void Update () { if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = Camera.main.WorldToScreenPoint(Input.mousePosition); gameObject.MoveTo (new Vector3 (0,mousePos.y,0), 3, 1); } } } Sorry if i made a mess, but i'm trying to learn basis to make a simple 2d game. If someone could gently help me to understand (not fix only the code ^^) it would be really nice. Thanks!

Viewing all articles
Browse latest Browse all 116

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>