帽子控制器腳本dom
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HatController : MonoBehaviour { public Text CountText; public Text OverText; private int count; // Use this for initialization void Start () { count = 0; OverText.text = ""; SetCountText(); } // Update is called once per frame void Update () { } void SetCountText() { CountText.text = "得分:" + count.ToString(); if (count >= 10) { OverText.text = "You Win"; count += 1; ; SetCountText(); } } private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Ball")) { collision.gameObject.SetActive(false); count++; SetCountText(); } Destroy(collision.gameObject); } }
小球生成腳本ide
using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameController : MonoBehaviour { public GameObject ball; private float time = 2f; private GameObject newball; // Use this for initialization void Start () { Vector3 screenPos = new Vector3(Screen.width, 0, 0); Vector3 moveWidth = Camera.main.ScreenToViewportPoint(screenPos); } private void FixedUpdate() { time -= Time.deltaTime; if(time<0) { time = Random.Range(0.5f, 2f); float posX = Random.Range(-10, 10); float posY = Random.Range(4, 9); Vector3 spawnPos = new Vector3(posX, posY, 0); newball = (GameObject)Instantiate(ball, spawnPos, Quaternion.identity); Destroy(newball, 2); } } // Update is called once per frame void Update () { } }
帽子移動腳本動畫
using System.Collections; using System.Collections.Generic; using UnityEngine; public class HatMove : MonoBehaviour { private float speed = 0.2f; // Use this for initialization void Start () { } // Update is called once per frame void Update () { float h = Input.GetAxis("Horizontal") * speed; Vector3 direction = new Vector3(h, 0, 0); this.GetComponent<Transform>().Translate(direction); } }
天鵝動畫腳本this
using System.Collections; using System.Collections.Generic; using UnityEngine; public class SwanMove : MonoBehaviour { private float speed = 0.06f; // Use this for initialization void Start () { this.transform.position = new Vector3(16, 3, 0); } // Update is called once per frame void Update () { transform.position += new Vector3(-speed, 0, 0); if(this.transform.position.x<-16) { this.transform.position = new Vector3(16, 3, 0); } } }
錄屏文件spa
連接:https://pan.baidu.com/s/1PDotVJxzLNVw9C1AiHrLAQ
提取碼:6d59code