Hi, m trying to instantiate a texture2d, when mouse hits on the object a a 2dcircle should appear at the hit point and every time i hit, a new 2dcircle should appear at the hit point…
var texture:Texture2D;
if( hit.collider.name == "TARGET" )
{
Instantiate(texture,hit.point,Quaternion.identity);
}
texture is not instantiating if i use this, is there any other way to do this, plz help
A Texture 2D is not an object but a variable type, therefore you cannot instantiate it. If you want to make a new Texture2D you can just use new Texture2D(width : int, height : int)
Though, looking at your piece of code, you don’t want to create a Texture2D but an object with a GUITexture component. You want to show a texture at the clicked object right? In that case, do the following:
var object = new GameObject();
object.addComponent("GUITexture");
you can adjust the object’s position, rotation and the GUITexture component you created to get the wanted result.
Note: if it’s text you want to display, you can replace GUITexture by GUIText