Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class cameraScript : MonoBehaviour {
- public GameObject unityChan;
- //characterController.csの、characterControllerクラスを宣言
- public characterController characterController;
- //gameOverScript.csの、gameOverScriptクラスを宣言
- public gameOverScript gameOverScript;
- public Text ScoreText;
- private int score = 0;
- private int gatePoint = 3;
- Transform playerTrans;
- void Start (){
- playerTrans = unityChan.GetComponent<Transform>();
- ScoreText.text = "Score: 0";
- }
- void FixedUpdate ()
- {
- float playerHeight = playerTrans.position.y;
- float currentCameraHeight = transform.position.y;
- float newHeight = Mathf.Lerp (currentCameraHeight, playerHeight, Time.deltaTime * 10);
- if (playerHeight > currentCameraHeight) {
- transform.position = new Vector3 (transform.position.x, newHeight, transform.position.z);
- }
- if (playerTrans.position.y >= gatePoint) {
- score += 10;
- gatePoint += 3;
- ScoreText.text = "Score: " + score.ToString ();
- }
- //ユニティちゃんの位置がカメラの位置-6よりも低くなった時
- if (playerTrans.position.y <= currentCameraHeight - 6) {
- //gameOverScript.csのgameOverScriptクラスのLoseメソッドを実行
- gameOverScript.Lose();
- //characterController.csのcharacterControllerクラスのStopメソッドを実行
- characterController.Destroy();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement