Unity3D 学习笔记001

 

//初始速度

public float movespeed = 5;

//移动   

if (Input.GetKey(KeyCode.A))

{

    go.transform.Translate(movespeed * Time.deltaTime * (-1), 0, 0, Space.World);

}

 

//开火=鼠标左键或者左ctrl

        if (Input.GetButtonDown("Fire1"))

 

//实例化 Transform (变换组件)

     Transform n = Instantiate(go, transform.position, transform.rotation);

 

//添加钢体

      Rigidbody rb = n.GetComponent<Rigidbody>();

            

 

 

//方向转换(0,0,1) forward 向前

      Vector3 fwd = transform.TransformDirection(Vector3.forward);

      rb.AddForce(fwd*30000);

 

//摧毁

      Destroy(n, 3.0f);

//镜头旋转

transform.Rotate(0, -25 * Time.deltaTime, 0, Space.Self);

 

//游戏界面 text 寻找

 

    GameObject.Find("Canvas").GetComponentInChildren<Text>().text= "弹药数量:" + m_ammo.ToString();

GameObject.Find("Text_fenshu").GetComponent<TextMesh>().text = "弹药数量:" + m_ammo.ToString();

GameObject.Find("Text_score").GetComponent<Text>().text = "2222";

 

//代码画一个 退出button

  if (GUI.Button(new Rect(180, 100, 60, 30), "退出"))

        {

            Application.Quit();

        }

 

//打印日志 用于调试

       Debug.Log("1111");

posted on 2019-12-22 21:50  股期勇气  阅读(504)  评论(0)    收藏  举报