方塊自轉腳本ide
using System.Collections;
using System.Collections.Generic;
using UnityEngine;this
public class RotatePickUp : MonoBehaviour {3d
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime);
}
}
orm
玩家控制器腳本blog
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;it
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody body;
public Text countText;
public Text winText;
private int count;
// Use this for initialization
void Start () {
body = GetComponent<Rigidbody>();
count = 0;
winText.text = "";
SetCountText();
}io
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
body.AddForce(movement * speed);
}form
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
count++;
SetCountText();
}
}class
void SetCountText()
{
countText.text = "Count:" + count.ToString();
if(count >= 12)
{
winText.text = "You Win";
count += 1; ;
SetCountText();
}
}
// Update is called once per frame
void Update () {
}
}
transform
攝像機控制器腳本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraContronller : MonoBehaviour {
public GameObject player;
private Vector3 offset;
public GameObject pickupPfb;
private GameObject[] obj1;
private int objCount = 0;
// Use this for initialization
void Start () {
offset = this.transform.position - player.transform.position;
obj1 = new GameObject[12];
for(objCount = 0; objCount<12; objCount++)
{
obj1[objCount] = GameObject.Instantiate(pickupPfb);
obj1[objCount].name = "pickup" + objCount.ToString();
obj1[objCount].transform.position = new Vector3(4 * Mathf.Sin(Mathf.PI / 6 * objCount), 1, 4 * Mathf.Cos(Mathf.PI / 6 * objCount));
}
}
void LateUpdate()
{
this.transform.position = player.transform.position + offset;
}
// Update is called once per frame
void Update () {
}
}