Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4.  
  5. public class cameraScript : MonoBehaviour {
  6.  
  7. public GameObject unityChan;
  8. //characterController.csの、characterControllerクラスを宣言
  9. public characterController characterController;
  10. //gameOverScript.csの、gameOverScriptクラスを宣言
  11. public gameOverScript gameOverScript;
  12. public Text ScoreText;
  13. private int score = 0;
  14. private int gatePoint = 3;
  15. Transform playerTrans;
  16.  
  17. void Start (){
  18. playerTrans = unityChan.GetComponent<Transform>();
  19. ScoreText.text = "Score: 0";
  20. }
  21.  
  22. void FixedUpdate ()
  23. {
  24. float playerHeight = playerTrans.position.y;
  25. float currentCameraHeight = transform.position.y;
  26. float newHeight = Mathf.Lerp (currentCameraHeight, playerHeight, Time.deltaTime * 10);
  27. if (playerHeight > currentCameraHeight) {
  28. transform.position = new Vector3 (transform.position.x, newHeight, transform.position.z);
  29. }
  30. if (playerTrans.position.y >= gatePoint) {
  31. score += 10;
  32. gatePoint += 3;
  33. ScoreText.text = "Score: " + score.ToString ();
  34. }
  35. //ユニティちゃんの位置がカメラの位置-6よりも低くなった時
  36. if (playerTrans.position.y <= currentCameraHeight - 6) {
  37. //gameOverScript.csのgameOverScriptクラスのLoseメソッドを実行
  38. gameOverScript.Lose();
  39. //characterController.csのcharacterControllerクラスのStopメソッドを実行
  40. characterController.Destroy();
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement