I want to instantiate a arrow as a gameobject where i click and destroy arrow when another mouse click and instantiate on another mouse position just like strategy game.
“Instantiate…where I click” is a bit complex in Unity because you are mapping your screen into a 3D space. Here is a starter script. Attach it to an object. The object will move to where you clicked. Note the oject is placed at 0.0 on the Z axis. Place this on an empty game object and you can modify it to Instantite game objects at a position.
using UnityEngine;
using System.Collections;
public class MoveObject : MonoBehaviour {
Plane plane;
void Start ()
{
plane = new Plane(Vector3.forward, Vector3.zero);
}
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
float fDist = 0.0f;
plane.Raycast (ray, out fDist);
transform.position = ray.GetPoint (fDist);
}
}
}