Build a site first
Then create a cube to adjust the angle
Bind script to spin him
void Start () { } // Update is called once per frame void Update () { transform.Rotate(new Vector3(15, 30, 45) * Time.deltaTime); } }
Save it as a prefab
Create a sphere as the control object Set up a script to bind to the sphere so we can control it
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Playercontraler : MonoBehaviour { public float speed=1f; private Rigidbody rb; public Text countText; public Text winText; private int count = 0; // Use this for initialization void Start () { rb = GetComponent<Rigidbody>(); winText.text = " "; SetCountText(); } void SetCountText() { countText.text = "count:" + count.ToString(); if (count>=12) { winText.text = "You Win"; } } private void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical); rb.AddForce(movement * speed); } private void OnTriggerEnter(Collider other) { if(other.gameObject.CompareTag("Pickup")) { other.gameObject.SetActive(false); count += 1; } } // Update is called once per frame void Update () { SetCountText(); } }
It can be manipulated, but the angle of the main camera is not perfect
Set up a script to bind to the camera so that it follows the sphere
And add the code and the prefabrication made before can automatically generate a circle at the beginning of the game
public class Cameracontraller : 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)); } } private void LateUpdate() { this.transform.position = player.transform.position + offset; } // Update is called once per frame void Update () { } }