原文https://blog.csdn.net/qq_20484877/article/details/81841190
1*创建物体
Create菜单下 3D Object菜单下Cube
1.1设置属性x100 z100作为地面
1.2在创建一个立方体物体
1.3 Create菜单下 3D Object菜单下Cube
1.4复制立方体
创建一个空物体放立方体
代码
#pragma strict
function Start () {
}
var speed : int =5;
var s1 : int =0;
var s2 : int =0;
var s3 : int =0;
var s4 : int =0;
var newobject : Transform;
var gutt : int =0;
var xms : int =0;
function Update () {
//移动物体
var x:float = Input.GetAxis("Horizontal")*Time.deltaTime*speed;
var z:float = Input.GetAxis("Vertical")*Time.deltaTime*speed;
if(gameObject.transform.position.x<-45){transform.Translate(300*Time.deltaTime,0,0);}
if(gameObject.transform.position.z<-45){transform.Translate(0,0,300*Time.deltaTime);}
if(gameObject.transform.position.x>45){transform.Translate(-300*Time.deltaTime,0,0);}
if(gameObject.transform.position.z>45){transform.Translate(0,0,-300*Time.deltaTime);}
transform.Translate(x,0,z);
//print("java"+x);
//创建物体
if(Input.GetButtonDown("Fire1")){
var n : Transform = Instantiate(newobject,transform.position,transform.rotation);
//交换方位
var fwd : Vector3 = transform.TransformDirection(Vector3.forward);
//给物体一个力
n.rigidbody.AddForce(fwd*2800);
gutt++;
//GUITText射击数
gameObject.Find("str").GetComponent(GUIText).text="射击数:"+gutt+"消灭数:"+xms;
}
//旋转功能
if(Input.GetKey(KeyCode.Q)){
transform.Rotate(0,-25*Time.deltaTime,0,Space.Self );
}
if(Input.GetKey(KeyCode.E)){
transform.Rotate(0,25*Time.deltaTime,0,Space.Self );
}
if(Input.GetKey(KeyCode.Z)){
transform.Rotate(-60*Time.deltaTime,0,0,Space.Self );
}
if(Input.GetKey(KeyCode.X)){
transform.Rotate(60*Time.deltaTime,0,0,Space.Self );
}
if(Input.GetKey(KeyCode.R)){
if(gameObject.transform.position.y>20){ transform.Translate(0,-300*Time.deltaTime,0);}
transform.Translate(0,3*Time.deltaTime,0);
}
if(Input.GetKey(KeyCode.F)){
if(gameObject.transform.position.y<1){transform.Translate(0,80*Time.deltaTime,0);}
transform.Translate(0,-3*Time.deltaTime,0);
}
}
结束脚本
#pragma strict
function Start () {
}
var s3 : int =0;
var s2 : int =0;
function Update () {
if(gameObject.transform.position.z>5)gameObject.Find("Capsule").GetComponent(AudioSource).enabled=true;
if(gameObject.transform.position.y<0){
s3=gameObject.Find("Camera").GetComponent(shji).xms++;
gameObject.Find("Capsule").GetComponent(AudioSource).enabled=false;
if(s3>60){
gameObject.Find("str").GetComponent(GUIText).text="恭喜通关,恭喜通关,恭喜通关";
gameObject.Find("Camera").GetComponent(shji).enabled=false;
gameObject.Find("dibo").GetComponent(restart).enabled=true;
}
Destroy(gameObject);
}
}
游戏分享
谢谢大家关注一下 [支持原创] @ 怪体杰
原文地址:https://www.cnblogs.com/jnhs/p/11433841.html
时间: 2024-11-05 20:24:55