What I currently have is a script to drag a 2D sprite. The problem is, the script runs off of the object to be dragged's tag.
However, If I have, for example, seventy of these same objects, then clicking and dragging on one will drag all objects with that tag.
To be more specific, my end-goal is to have potentially endless creeps (meaning several duplicates) spawning. clicking on any one creep and dragging it will only drag that one creep. Will I need a ton of tags to achieve this or is there a better way?
Here is my current code. If you reply with code, feel free to use either javascript or C#, I'm not picky.
Thanks for your input(s)!
#pragma strict
function Update ()
{
if (Input.GetMouseButton(0))
{
var hitInfo : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if(hitInfo.collider.tag == "Guard")
{
this.transform.position.x = hitInfo.point.x;
this.transform.position.y = hitInfo.point.y;
Debug.Log("object clicked: "+hitInfo.collider.tag);
}
}
}
↧