2015-10-24 39 views
0

我在Unity編程遊戲。我試圖在用戶每次點擊界面時在空間中產生一個球體。我可以產生球體,但球體總是在(200,200,0)和(400,400,0)左右的座標上,但球體應該在指針在屏幕上的位置產生。這是我的代碼在下面,有人可以幫忙嗎?我正在用C#編寫:在Unity中產卵:領域飛出範圍

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); 
} 

} 

回答