// 物件跟隨鏡頭移動
using UnityEngine;
usinng System.Collections;
public class CameraController : MonoBehoviour
{
public gameObject palyer;
public Vector3 offset;
void Start()
{
offset = transform.position;
}
void Update()
{
transform.position = palyer.transform.position + offest;
}
}
// 物件中心旋轉
using UnityEngine;
using System.Collections;
public class Rotetor ; MonoBehaviour
{
void Update() {
transform.Rotate(new Vector3(15,30,45) * Time.daltaTime);
}
}
// 觸碰到就消失
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForcce(movement * speed * TIme.deltaTime);
}
// 這裡rigidbody的Trigger選項必須勾上
// tag就在tag裡加上一個Element
// tag是分大小寫的、注意
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
}
}
}
// 加入GUI、里面的Object要手動的拖到Script里
// 創建GUI控件前、先新增空物件
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public GUIText counttext;
public GUIText minText;
private int count;
void Start() {
count = 0;
SetCountText();
minText.text= "";
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForcce(movement * speed * TIme.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "PickUp")
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
// ToString把所有類型轉為String
countText.text = "Count: "+count.ToString();
if (count >= 12)
{
mintext.text = "YOU WIN";
}
}
}