2015-10-24 29 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); 
} 

} 

回答