im making an android game and i want to make it so that when you tap somewhere on the screen a cube will instantiate there but im not sure how to go about it
Instantiation
http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
Touch
http://unity3d.com/support/documentation/ScriptReference/TouchPhase.html
Basic touch and Instantiation, not optimized and not suggested for practical use in it’s basic state:
using UnityEngine;
using System.Collections;
public class touchSpawnExample : MonoBehaviour {
public GameObject itemToSpawn;
private GameObject itemToSpawnInstance;
void Update()
{
if( Input.touchCount == 1 )
{
Touch touch = Input.touches[0];
switch( touch.phase )
{
case TouchPhase.Began:
itemToSpawnInstance = (GameObject)Instantiate( itemToSpawn, Vector3.zero, Quaternion.identity );
break;
case TouchPhase.Moved:
// track touch movement and doStuff here
break;
case TouchPhase.Ended:
// track touch lifted off screen and doStuff here
break;
default:
break;
}
}
}
}