Unityでゲームをプログラミングしています。ユーザーがインターフェイスをクリックするたびに、空間に球を生成しようとしています。球体をスポーンできますが、球体は常に (200,200, 0) と (400,400,0) 付近の座標にありますが、球体はポインターが画面上にある場所にスポーンする必要があります。以下は私のコードです。誰か助けてくれますか?私はC#で書いています:
using UnityEngine;
using System.Collections;
public class myscript : MonoBehaviour {
//initialize a circle
public GameObject Node;
public float cooldown = 1;
bool clicker;
float clicktime = 0;
GameObject node; //reference to the prefab
// Use this for initialization
void Start () {
}
//In everyframe you can
void Update () {
clicker = Input.GetMouseButtonDown(0); //obtaining the input
clicktime += Time.deltaTime;
}
//Check whether you can shoot
void FixedUpdate(){
if (clicker == true && clicktime >= cooldown) { //if the clicker is clicked and the previos clicking is done
SpawnCircle(); //spawn a circle
clicktime = 0; //reset timer
}
}
void SpawnCircle(){
//this creates a new game object
x = Input.mousePosition.x
y = Input.mousePosition.
node = GameObject.Instantiate (Node,Input.mousePosition,Quaternion.identity) as GameObject;
//settings that we initalize our object with
//node.transform.position = new Vector3(Input.mousePosition.x, Input.mousePosition.y,0);
}
}