小球滾動

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : 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 () {
		
	}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour {
	public float speed;
	private Rigidbody rb;
	public Text countText;
	public Text winText;
	private int count;
	// Use this for initialization
	void Start () {
		rb=GetComponent<Rigidbody>();
		count = 0;
		winText.text = "";
		SetCountText();
	}
	
	void FixedUpdate() {
		float moveHorizontal=Input.GetAxis("Horizontal");
		float moveVerticl=Input.GetAxis("Vertical");
		Vector3 movement=new Vector3(moveHorizontal,0,moveVerticl);
		rb.AddForce(movement * speed);
	}

	void OnTriggerEnter(Collider other) {
		if (other.gameObject.CompareTag("PickUp"))
		{
			other.gameObject.SetActive(false);
			count += 1;
			SetCountText();
		}
	}

	void SetCountText()
	{
		countText.text = "Count:" + count.ToString();
		if (count>= 12)
		{
			winText.text = "You Win!";
		}
	}
	// Update is called once per frame
	void Update () {
		
	}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotatePickUp : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		this.transform.Rotate(new Vector3(15,30,45)*Time.deltaTime);
	}
}
相關文章
相關標籤/搜索