旋转:
Object cy = gameObject.Find("earth").transform;
transform.RotateAround(cy.position,Vector3.up,200*Time.DeltaTime);//(某一点,沿着那一点的y轴旋转,旋转的速度)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class sheji : MonoBehaviour{
// Start is called before the first frame update
void Start()
{
}
private int speed = 5;
public int number = 0;
static public int number_passed = 0;
public Transform newobject;
// Update is called once per frame
void Update(){
float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed*5;
float z = Input.GetAxis("Vertical") * Time.deltaTime * speed*5;
//移动
transform.Translate(x,0,z);
//print(x);
// 是否为开火键
//if (Input.GetButtonDown("Fire1")) {
if (Input.GetKeyDown(KeyCode.J))
{
Transform n = Instantiate(newobject, transform.position, transform.rotation);
Vector3 fwd = transform.TransformDirection(Vector3.forward);//坐标转换
//n.rigidbody.AddForce(fwd * 2800);
n.GetComponent<Rigidbody>().AddForce(fwd * 2800);
number++;
//修改text的值,这里一定要加入:using UnityEngine.UI;
//Canvas / textnumber和textnumber效果是一样的
//GameObject表示脚本在哪个物体上,就是哪个物体对象
Text text = GameObject.Find("textnumber").GetComponent<Text>();
text.text= "射弹数:" + number;
print("射弹数:" + number);
}
if (number_passed == 1) {
Text text = GameObject.Find("textnumber").GetComponent<Text>();
text.text = "射弹数:" + number+" 完成数:"+ number_passed;
print("射弹数:" + number);
}
//旋转
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)){
//X,Y,Z,
transform.Rotate(-25 * Time.deltaTime,0, 0, Space.Self);
}
if (Input.GetKey(KeyCode.C))
{
transform.Rotate(25 * Time.deltaTime,0, 0, Space.Self);
}
//升高降低镜头
if (Input.GetKey(KeyCode.H))
{
transform.Translate(0,5 * Time.deltaTime*4, 0, Space.Self);
}
if (Input.GetKey(KeyCode.N))
{
transform.Translate(0, -5 * Time.deltaTime*4, 0, Space.Self);
}
}
}