Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.SocialPlatforms.Impl;
- using UnityEngine.UI;
- public class Level01PlayerControllerTest : MonoBehaviour
- {
- // Role: ???
- private bool moveRight = false;
- private bool moveLeft = false;
- private bool moveUp = true;
- private bool moveDown = false;
- public float driveSpeed;
- public float switchSpeed;
- private float acc = 0.005f;
- private Rigidbody2D rb2d;
- public GameObject level01Player;
- //private Animator animator;
- private bool switchLeft = false;
- private bool switchRight = true;
- // Timer
- private float timer = 0.0f;
- private int seconds;
- private Level01DestroyByContact destroyByContact;
- public TMPro.TMP_Text level01ScoreText;
- public TMPro.TMP_Text level01GameTimeText;
- public TMPro.TMP_Text level01GameTimeScoreText;
- public TMPro.TMP_Text level01LivesScoreText;
- public TMPro.TMP_Text level01FinalScoreText;
- public GameObject newLevel01GameTimeText;
- public GameObject newLevel01HighScoreText;
- public int level01Score;
- public int level01GameTimeScore;
- public int level01LivesScore;
- public int level01FinalScore;
- public int level01HighScore;
- public int level01GameTime;
- private bool newLevel01LongestGameTime;
- private bool newLevel01HighScore;
- public int level01NewLongestGameTimeBonus;
- public TMPro.TMP_Text level01NewLongestGameTimeBonusText;
- public int level01RemainingLivesBonus;
- public TMPro.TMP_Text level01RemainingLivesBonusText;
- public TMPro.TMP_Text testBonusText;
- //Test Variables 02
- public Transform laneAPoint;
- public Transform laneBPoint;
- public Transform laneCPoint;
- [Tooltip("How long the movement will take in seconds.")]
- public float moveDuration = 2;
- public bool inLaneA = false;
- public bool inLaneB = false;
- public bool inLaneC = false;
- private void Start()
- {
- GameObject destroyByContactObject = GameObject.FindWithTag("Player");
- if (destroyByContactObject != null)
- {
- destroyByContact = destroyByContactObject.GetComponent<Level01DestroyByContact>();
- }
- if (destroyByContact == null)
- {
- Debug.Log("Cannot find 'DestroyByContact' script");
- }
- rb2d = transform.GetComponent<Rigidbody2D>();
- //animator = GetComponent<Animator>();
- switchLeft = false;
- switchRight = false;
- inLaneA = false;
- inLaneB = true;
- inLaneC = false;
- level01HighScore = PlayerPrefs.GetInt("Level01HighScore", 0);
- level01GameTime = PlayerPrefs.GetInt("Level01LongestGameTime", 0);
- newLevel01LongestGameTime = false;
- newLevel01GameTimeText.SetActive(false);
- //animator.SetBool("SwitchLeft", false);
- //animator.SetBool("SwitchRight", false);
- }
- void Update()
- {
- // Timer
- // Seconds in Float
- timer += Time.deltaTime;
- // Convert Time Float to Int
- seconds = (int)(timer);
- // Print(seconds)
- level01Score = seconds;
- level01ScoreText.text = "Time: " + level01Score;
- level01GameTime = level01Score;
- // Establishing Final Score
- // Establishing Final Score - Game Time
- level01GameTimeText.text = "Game Time : " + level01Score;
- // Establishing Final Score - Game Time Score
- level01GameTimeScore = level01GameTime * 5;
- level01GameTimeScoreText.text = "Time Score: " + level01GameTimeScore;
- // Establishing Final Score - Game Time Bonus Score
- level01NewLongestGameTimeBonusText.text = "Time Bonus: " + level01NewLongestGameTimeBonus;
- // Establishing Final Score - Lives Bonus
- level01RemainingLivesBonus = destroyByContact.level01LivesBonus;
- level01RemainingLivesBonusText.text = "Lives Bonus: " + level01RemainingLivesBonus;
- testBonusText.text = "From DBC " + level01RemainingLivesBonus;
- // Establishing Final Score - Final Score
- level01FinalScore = level01GameTimeScore + level01NewLongestGameTimeBonus + level01RemainingLivesBonus;
- level01FinalScoreText.text = "Final Score: " + level01FinalScore;
- // Establishing High Score
- level01HighScore = level01FinalScore;
- SetLongestGameTime();
- }
- private void FixedUpdate()
- {
- // Activates Move Up Animation & Movement
- if (moveUp == true)
- {
- driveSpeed += acc * Time.deltaTime;
- transform.Translate(driveSpeed * Time.deltaTime * Vector3.up);
- }
- // Activates Movement Left & Right Movement
- if (switchLeft == true && switchRight == false)
- {
- if (inLaneA == false && inLaneB == true && inLaneC == false)
- {
- // remember, 10 - 5 is 5, so target - position is always your direction.
- Vector3 dir = laneAPoint.position - transform.position;
- // magnitude is the total length of a vector.
- // getting the magnitude of the direction gives us the amount left to move
- float dist = dir.magnitude;
- // this makes the length of dir 1 so that you can multiply by it.
- dir = dir.normalized;
- // the amount we can move this frame
- float move = switchSpeed * Time.deltaTime;
- // limit our move to what we can travel.
- if(move > dist) move = dist;
- // apply the movement to the object.
- transform.Translate( dir * move);
- }
- else if (inLaneA == false && inLaneB == false && inLaneC == true)
- {
- // remember, 10 - 5 is 5, so target - position is always your direction.
- Vector3 dir = laneBPoint.position - transform.position;
- // magnitude is the total length of a vector.
- // getting the magnitude of the direction gives us the amount left to move
- float dist = dir.magnitude;
- // this makes the length of dir 1 so that you can multiply by it.
- dir = dir.normalized;
- // the amount we can move this frame
- float move = switchSpeed * Time.deltaTime;
- // limit our move to what we can travel.
- if(move > dist) move = dist;
- // apply the movement to the object.
- transform.Translate( dir * move);
- }
- }
- else if (switchRight == true && switchLeft == false)
- {
- if (inLaneA == true && inLaneB == false && inLaneC == false)
- {
- // remember, 10 - 5 is 5, so target - position is always your direction.
- Vector3 dir = laneBPoint.position - transform.position;
- // magnitude is the total length of a vector.
- // getting the magnitude of the direction gives us the amount left to move
- float dist = dir.magnitude;
- // this makes the length of dir 1 so that you can multiply by it.
- dir = dir.normalized;
- // the amount we can move this frame
- float move = switchSpeed * Time.deltaTime;
- // limit our move to what we can travel.
- if(move > dist) move = dist;
- // apply the movement to the object.
- transform.Translate( dir * move);
- }
- else if (inLaneA == false && inLaneB == true && inLaneC == false)
- {
- // remember, 10 - 5 is 5, so target - position is always your direction.
- Vector3 dir = laneCPoint.position - transform.position;
- // magnitude is the total length of a vector.
- // getting the magnitude of the direction gives us the amount left to move
- float dist = dir.magnitude;
- // this makes the length of dir 1 so that you can multiply by it.
- dir = dir.normalized;
- // the amount we can move this frame
- float move = switchSpeed * Time.deltaTime;
- // limit our move to what we can travel.
- if(move > dist) move = dist;
- // apply the movement to the object.
- transform.Translate( dir * move);
- }
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.CompareTag("LaneA"))
- {
- inLaneA = true;
- inLaneB = false;
- inLaneC = false;
- }
- else if (other.CompareTag("LaneB"))
- {
- inLaneA = false;
- inLaneB = true;
- inLaneC = false;
- }
- else if (other.CompareTag("LaneC"))
- {
- inLaneA = false;
- inLaneB = false;
- inLaneC = true;
- }
- }
- public void SwitchLeft()
- {
- switchLeft = true;
- switchRight = false;
- }
- public void SwitchRight()
- {
- switchRight = true;
- switchLeft = false;
- }
- public void SetLongestGameTime()
- {
- //Updates Longest Game Time when Player achieves a New Longest Game Time
- if (level01GameTime > PlayerPrefs.GetInt("Level01LongestGameTime", 0))
- {
- PlayerPrefs.SetInt("Level01LongestGameTime", level01GameTime);
- newLevel01LongestGameTime = true;
- WillEnableGameTime();
- }
- }
- public void SetHighScore()
- {
- // Updates High Score for Level 01
- if (level01HighScore > PlayerPrefs.GetInt("Level01HighScore"))
- {
- PlayerPrefs.SetInt("Level01HighScore", level01HighScore);
- newLevel01HighScore = true;
- WillEnableHighScore();
- }
- //SetLongestGameTime();
- }
- IEnumerator HideShowNewGameTime()
- {
- // Displays New Longest Game Time for 3 Seconds
- if (newLevel01LongestGameTime == true)
- {
- yield return new WaitForSeconds(3f);
- newLevel01LongestGameTime = false;
- WillEnableGameTime();
- }
- }
- IEnumerator HideShowNewHighScore()
- {
- // Displays New High Score for 3 Seconds
- if (newLevel01LongestGameTime == true)
- {
- yield return new WaitForSeconds(3f);
- newLevel01HighScore = false;
- WillEnableHighScore();
- }
- }
- public void WillEnableGameTime()
- {
- // Displays New Longest Game Time Text
- if (newLevel01LongestGameTime == true)
- {
- newLevel01GameTimeText.SetActive(true);
- StartCoroutine(HideShowNewGameTime());
- level01NewLongestGameTimeBonus = 100;
- }
- // Destroys New Longest Game Time Text
- else if (newLevel01LongestGameTime == false)
- {
- newLevel01GameTimeText.SetActive(false);
- Destroy(newLevel01GameTimeText);
- }
- }
- public void WillEnableHighScore()
- {
- // Displays New High Score Text
- if (newLevel01HighScore == true)
- {
- newLevel01HighScoreText.SetActive(true);
- StartCoroutine(HideShowNewHighScore());
- }
- // Destroys New Longest Game Time Text
- else if (newLevel01HighScore == false)
- {
- newLevel01HighScoreText.SetActive(false);
- Destroy(newLevel01HighScoreText);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement