Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, yMin, yMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public Boundary boundary;
//Shot type 1 (Green)
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
private float nextFire;
//Shot type 2 (Blue)
public GameObject shot_2;
public Transform shotSpawn_2;
public float fireRate_2;
private float nextFire_2;
//Shot type 3 (Green Big)
public GameObject shot_3;
public Transform shotSpawn_3;
public float fireRate_3;
private float nextFire_3;
public Text score;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "GoldStar")
{
HealthScript.healthValue = HealthScript.healthValue + 100;
ScoreScript.scoreValue += 20;
speed = speed + 2.5f;
fireRate_3 = 1.0f;
fireRate_2 = 1.0f;
Destroy(other.gameObject);
}
if (other.tag == "PowerUp")
{
HealthScript.healthValue = HealthScript.healthValue + 100;
Destroy(other.gameObject);
}
if (other.tag == "Shot_UFO")
{
HealthScript.healthValue = HealthScript.healthValue - 25;
Destroy(other.gameObject);
}
if (other.tag == "Shot_Boss")
{
HealthScript.healthValue = HealthScript.healthValue - 50;
Destroy(other.gameObject);
}
if (other.tag == "PowerUp2")
{
HealthScript.healthValue = HealthScript.healthValue + 50;
Destroy(other.gameObject);
}
if (other.tag == "PowerUp3")
{
HealthScript.healthValue = HealthScript.healthValue + 25;
Destroy(other.gameObject);
}
if (other.tag == "LightningBolt")
{
speed = speed + 2.5f;
fireRate_3 = fireRate_3 - 2.5f;
if (fireRate_3 <= 0)
{
fireRate_3 = 1;
}
Destroy(other.gameObject);
}
}
void Update()
{
if (Input.GetKey("space") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
if (Input.GetKey("q") && Time.time > nextFire_2)
{
nextFire_2 = Time.time + fireRate_2;
Instantiate(shot_2, shotSpawn_2.position, shotSpawn_2.rotation);
}
if (Input.GetKey("e") && Time.time > nextFire_3)
{
nextFire_3 = Time.time + fireRate_3;
Instantiate(shot_3, shotSpawn_3.position, shotSpawn_3.rotation);
}
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Rigidbody2D rigidbody = GetComponent<Rigidbody2D>();
rigidbody.velocity = new Vector2(moveHorizontal, moveVertical) * speed;
rigidbody.position = new Vector2
(
Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax),
Mathf.Clamp(rigidbody.position.y, boundary.yMin, boundary.yMax)
);
}
}