Roll-a-Ball教程学习笔记(未整理)

来源:互联网 发布:红警网络进不去 编辑:程序博客网 时间:2024/04/20 01:53
Roll-a-Ball教程学习笔记(未整理)


环境:Unity3D5 5.1.1f1
作者:kagula


简介
  资料资料[1]学习Unity3D基本概念,并做了笔记。


注意事项
[1]
FixedUpdate事件,响应物理动作,同帧率无关。


[2]
关键词(函数名)后面跟上Ctrl+',打开Help document.


[3]
关于空间
Vector3(LeftOrRight, UpOrDown, ForwardOrBackward)


[4]添加了“Rigidbody”component的游戏对象可以接受外力和扭矩力,
并且像真实的物体一样接受摩擦力和重力。


[5]LastUpdate事件,所有item运算完成后,就激发这个事件。


[6]prefab的概念就像个“原始模板”,对它的修改会影响它的所有实例。


[7]静态对象不要移动它,否则会导致刷新静态对象cache,性能会降低,
   所以会动的东西,要加上RigidBody component,这样就不是“静态对象”了,改进了效率.


[8]Collider的Is Trigger属性,是不是意思说,其它对象碰到它,会触发OnTriggerEnter事件?


教程中用到的源代码

PlayController.cs源码清单

using UnityEngine;using UnityEngine.UI;using System.Collections;public class PlayerController : MonoBehaviour {public float speed;public Text countText;public Text winText;private Rigidbody rb;private int count;void Start(){rb = GetComponent<Rigidbody> ();count = 0;countText.text = "Count:" + count.ToString ();winText.text = "";SetCountText();}void FixedUpdate(){float moveHorizontal = Input.GetAxis ("Horizontal");float moveVertical = Input.GetAxis ("Vertical");Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);rb.AddForce (movement * speed);}void OnTriggerEnter(Collider other){if (other.gameObject.CompareTag ("Pick Up")) {other.gameObject.SetActive(false);count = count + 1;SetCountText();}}void SetCountText(){countText.text = "Count:" + count.ToString ();if (count >= 10) {winText.text = "You Win";}}}


CameraController.cs源码清单

using UnityEngine;using System.Collections;public class CameraController : MonoBehaviour {public GameObject player;private Vector3 offset;// Use this for initializationvoid Start () {offset = transform.position - player.transform.position;}// Update is called once per framevoid Update () {transform.position = player.transform.position + offset;}}


Rotator.cs源码清单

using UnityEngine;using System.Collections;public class Rotator : MonoBehaviour {// Update is called once per framevoid Update () {transform.Rotate (new Vector3 (13, 30, 45) * Time.deltaTime);}}




参考资料
[1]Roll-a-Ball教程地址
https://unity3d.com/learn/tutorials/projects/roll-a-ball/creating-collectables
0 0