How to put a new sprite to the point where the mouse was clicked?
Here's how it should look:
Vector3 posSprite
= new Vector3
();posSprite.x = Input.mousePosition.x - (float)Screen.width / 2;
posSprite.y = Input.mousePosition.y - (float)Screen.height / 2;
GameObject go = NGUITools.AddChild( spriteParent, prefabMySprite);
MyScriptControlUISprite script = go.GetComponent<MyScriptControlUISprite>();
script.Setup(posSprite);
I need to first get the coordinates for the sprite
and then I have them initialize event "Start"
public class MyScriptControlUISprite : MonoBehaviour {
private Vector3 _startPosition;
public void Setup(Vector3 startPosition)
{
_startPosition = startPosition;
}
void Start()
{
gameObject.GetComponent<UISprite>().transform.localPosition = _startPosition;
}
}
In this example, it works correctly only for the resolution of 16: 9