I am making a game where I have to move orbs around the board to match them up. I have the orbs spawning, but I am having a problem getting the orb to move. I want it to move the orb that is clicked on, while the mouse is held down and once I release the mouse the orb is set where it is at when the mouse button is released. I get no errors when trying to move the orb. I have debug logs in each string of code and the console does show each of the debug logs when I try to move the orb. The orb even gets placed into the GameObject variable I set to store the orb I clicked on. I am doing this in C# so help in that would be appreciated. Here is my code if anyone can help me figure out why the orbs do not move.
using UnityEngine;
using System.Collections;
public class orbScript : MonoBehaviour {
Vector3 mouseLoc;
Vector3 moveLoc;
Vector3 moveObj;
public GameObject captureOrb;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//move orb by dragging mouse
if(Input.GetButtonDown ("Fire1")) {
Debug.Log ("Mouse clicked");
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
Debug.Log ("Raycast sent out");
if (Physics.Raycast (ray, out hit, Mathf.Infinity)) {
//capture what orb was clicked on
captureOrb = hit.collider.gameObject;
Debug.Log ("orb selected");
// assign mouse position property of input to mouse location variable
mouseLoc = Input.mousePosition;
Debug.Log ("mouse position assigned");
// set z position in mouse location before conversion
mouseLoc.z = -8.9f;
Debug.Log ("z position of mouse locked");
// convert screen space location of mouse to world space
moveLoc = Camera.main.ScreenToWorldPoint (mouseLoc);
Debug.Log ("converted mouse location to world space");
//convert orb position to move
moveObj = captureOrb.GetComponent<Transform>().position;
Debug.Log ("orb position converted to move");
// move orb to mouse location in world space
moveObj = moveLoc;
Debug.Log ("moved orb");
}
}
}
}