using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody2D rb2d;
private int count;
private int LevelNo;
private int LevelChange;
void Start()
{
rb2d = GetComponent <Rigidbody2D> ();
count = 1;
winText.text = "";
SetCountText ();
LevelNo = 0;
LevelChange = 0;
}
void OnTriggerEnter2D (Collider2D other)
{
if (other.gameObject.CompareTag ("PickUp"))
{
other.gameObject.SetActive (false);
count = count - 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Warp cores to stabilize: " + count.ToString ();
if (count == 0)
{
LevelChange = LevelNo + 1;
winText.text = "You saved the warp core!";
Application.LoadLevel ("Level " + LevelChange);
count = 1;
}
}
void FixedUpdate()
{
if (speed == 10) {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb2d.AddForce (movement * speed);
}
}
}
This script also controls scoring and movement.,using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody2D rb2d;
private int count;
private int LevelNo;
private int LevelChange;
void Start()
{
rb2d = GetComponent <Rigidbody2D> ();
count = 1;
winText.text = "";
SetCountText ();
LevelNo = 0;
LevelChange = 0;
}
void OnTriggerEnter2D (Collider2D other)
{
if (other.gameObject.CompareTag ("PickUp"))
{
other.gameObject.SetActive (false);
count = count - 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Warp cores to stabilize: " + count.ToString ();
if (count == 0)
{
LevelChange = LevelNo + 1;
winText.text = "You saved the warp core!";
Application.LoadLevel ("Level " + LevelChange);
count = 1;
}
}
void FixedUpdate()
{
if (speed == 10) {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb2d.AddForce (movement * speed);
}
}
}
This script also controls the score and movement.