I am new to unity. I am working on cake maker like game for android device. I am facing a difficulty in dragging objects from cabinet to table. On table i want to mix them in a jar. These are Many items. So, I cannot do it by separating them using unity Tags. How to make a generic way to drag them on table?
I am using this code but its not working for me.
using UnityEngine;
using System.Collections;
public class DragObjects : MonoBehaviour {
Ray ray;
RaycastHit hit;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit))
{
if (hit.collider.tag == "oil")
{
OnMouseDrag();
}
}
}
}
void OnMouseDrag()
{
Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
point.x = gameObject.transform.position.x;
gameObject.transform.position = point;
}
}