I have created a script which was supposed to instantiate gameobject according to mouse position but something has went wrong. And it is only being instantiated at one position and in the middle of the screen.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LineInstantiater : MonoBehaviour {
public GameObject lineprefab;
private GameObject linehandler;
private Vector3 mousepos;
void Update(){
if (Input.GetMouseButton (0)) {
mousepos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
linehandler = Instantiate (lineprefab,Camera.main.ScreenToWorldPoint(Input.mousePosition),Quaternion.identity) as GameObject ;
linehandler.transform.position = mousepos;
}
}
}
Please tell me what is wrong with my script.
See Question&Answers more detail:os