首页 > 其他 > 详细

鼠标点击地面获取坐标

时间:2014-04-22 22:01:21      阅读:640      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
//特效代码,射线点击地面产生特效

var moveThis : GameObject;
var hit : RaycastHit;
var createThis : GameObject[];
var cooldown : float;
var changeCooldown : float;
var selected:int=0;
var writeThis:GUIText;
private var rndNr:float;
function Start () {
writeThis.text=selected.ToString();
}

function Update () {
if(cooldown>0){cooldown-=Time.deltaTime;}
if(changeCooldown>0){changeCooldown-=Time.deltaTime;}

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);

if (Physics.Raycast (ray, hit)) {
// Create a particle if hit
moveThis.transform.position=hit.point;

if(Input.GetMouseButton(0)&&cooldown<=0){
Instantiate(createThis[selected], moveThis.transform.position, moveThis.transform.rotation);


/*rndNr=Mathf.Floor(Random.value*createThis.length);
Instantiate(createThis[rndNr], moveThis.transform.position, moveThis.transform.rotation);
moveThis.transform.position.x+=Random.value*12-Random.value*12;


rndNr=Mathf.Floor(Random.value*createThis.length);
Instantiate(createThis[rndNr], moveThis.transform.position, moveThis.transform.rotation);
moveThis.transform.position.x+=Random.value*12-Random.value*12;



rndNr=Mathf.Floor(Random.value*createThis.length);
Instantiate(createThis[rndNr], moveThis.transform.position, moveThis.transform.rotation);
moveThis.transform.position.x+=Random.value*12-Random.value*12;*/




cooldown=0.1;
}



//Instantiate (particle, hit.point, transform.rotation);

}


if (Input.GetKeyDown("space") && changeCooldown<=0)
{
    selected+=1;
        if(selected>(createThis.length-1)) {selected=0;}
    
    writeThis.text=selected.ToString();
    changeCooldown=0.1;
}

if (Input.GetKeyDown(KeyCode.UpArrow) && changeCooldown<=0)
{
    selected+=1;
        if(selected>(createThis.length-1)) {selected=0;}
    
    writeThis.text=selected.ToString();
    changeCooldown=0.1;
}

if (Input.GetKeyDown(KeyCode.DownArrow) && changeCooldown<=0)
{
    selected-=1;
        if(selected<0) {selected=createThis.length-1;}
    
    writeThis.text=selected.ToString();
    changeCooldown=0.1;
}




}
bubuko.com,布布扣
bubuko.com,布布扣
var destroyTime:float=5;

function Start () {
Destroy (gameObject, destroyTime);
}
function Update () {
}
bubuko.com,布布扣

 

鼠标点击地面获取坐标,布布扣,bubuko.com

鼠标点击地面获取坐标

原文:http://www.cnblogs.com/sy88/p/3679881.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!