分享

Roll a ball

 三维记忆 2019-11-19

PlayerController

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; SetCountText (); winText.text = ""; } 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 >= 12) { winText.text = "You Win!"; } } }

Rotator

using UnityEngine;using System.Collections;public class Rotator : MonoBehaviour { void Update () { transform.Rotate (new Vector3 (15, 30, 45) * Time.deltaTime); } }



CameraController

using UnityEngine;using System.Collections;public class CameraController : MonoBehaviour { public GameObject player; private Vector3 offset; void Start () { offset = transform.position - player.transform.position; } void LateUpdate () { transform.position = player.transform.position + offset; } }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多