Hi everyone,
Im having a bit of an issue trying to implement a drag and drop system in my game. I watched a video on youtube http://www.youtube.com/watch?v=ZCKiuu1qcRY) of it in Javascript and it work perfectly but when i converted it to C# is just gave me 2 errors.
using UnityEngine;
using System.Collections;
public class Turret : MonoBehaviour
{
private Ray ray;
private RaycastHit hit;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
OnMouseDrag();
}
void OnMouseDrag()
{
if (Input.GetMouseButton(1))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
transform.position.x = hit.point.x;
transform.position.y = hit.point.y;
}
}
}
}
im getting errors on the lines:
transform.position.x = hit.point.x;
transform.position.y = hit.point.y;
The errors say “Cannot modify the return value of ‘Unity.Engine.Transform.position’ because it is not a variable”.
I know that im probably doing something stupid but can anyone give me some advice?