App Development With Unity

lava hunt

 

Click on the Picture above to see an App called Lava Hunt that i published as a personal project.

The point of the game is to avoid lava flowing down and remain alive for as long as possible.

Below are some examples of C# code I used to control the assets in the game.

 

// Play Music in Unity

using UnityEngine;
using System.Collections;

public class music : MonoBehaviour {

public AudioSource lava_music;
// Use this for initialization
void Start () {

lava_music = (AudioSource)gameObject.AddComponent<AudioSource>();
AudioClip lava_clip;
lava_clip = (AudioClip)Resources.Load(“SFX/LavaMusic”);
lava_music.clip = lava_clip;
lava_music.loop = true;
lava_music.Play ();

}

// Update is called once per frame
void Update () {

}
}
// Detect Collisions in Unity

using UnityEngine;
using System.Collections;

public class p1collide : MonoBehaviour {

public static int lives = 3;
void OnCollisionEnter2D (Collision2D col) {

if (col.gameObject.tag == “Lava”) {

lives–;
if (lives == 0) {
Destroy (gameObject);
Reload.gameOver = true;
Destroy (this);
}

}

if (col.gameObject.tag == “WaterTile”) {

score.multiplier++;
inventoryText.amount += 10;
Reload.globalspeed -= 3;
if (Reload.globalspeed < 5) {
Reload.globalspeed = 5;
}
}

if (col.gameObject.tag == “lifeTile”) {

lives++;
}

}
}
// Movement Script for the Main Player
using UnityEngine;
using System.Collections;

public class player1movement : MonoBehaviour {

Vector3 playerPos;
float xPos;
float yPos;
public float xConstraint =50;
public float yConstraint =28;
public int moveDistance =4;
public bool WASD = false;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

yPos = transform.position.y;
xPos = transform.position.x;

if(WASD == false)
{
if(Input.GetKeyDown( KeyCode.UpArrow))
{
yPos = yPos+moveDistance;
}
if(Input.GetKeyDown( KeyCode.DownArrow))
{
yPos = yPos-moveDistance;
}

if(Input.GetKeyDown( KeyCode.RightArrow))
{
xPos = xPos+moveDistance;
}
if(Input.GetKeyDown( KeyCode.LeftArrow))
{
xPos = xPos-moveDistance;
}
}

if(WASD == true)
{
if(Input.GetKeyDown( KeyCode.W))
{
yPos = yPos+moveDistance;
}
if(Input.GetKeyDown( KeyCode.S))
{
yPos = yPos-moveDistance;
}

if(Input.GetKeyDown( KeyCode.D))
{
xPos = xPos+moveDistance;
}
if(Input.GetKeyDown( KeyCode.A))
{
xPos = xPos-moveDistance;
}
}

playerPos = new Vector3(Mathf.Clamp(xPos, -xConstraint, xConstraint), Mathf.Clamp(yPos, -yConstraint, yConstraint), 0);
transform.position = playerPos;
}
}

//Scoring system and highscore saving system

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class score : MonoBehaviour {

public Text counterText;
public static int multiplier = 1;
int scoreText = 0;
int subcounter = 0;
int level =1;
// Use this for initialization
void Start () {
counterText = GetComponent<Text>() as Text;

}

// Update is called once per frame
void Update () {

if (scoreText > 7000*level) {
Reload.globalspeed=60;
level++;
}

subcounter++;
counterText.text = scoreText.ToString(“00”);
if (subcounter >= 50 && Reload.gameOver == false) {
scoreText = scoreText + multiplier;
subcounter = 0;
} else if (Reload.gameOver == true){
StoreHighscore(scoreText);

}
}

void StoreHighscore(int newHighscore)
{
int oldHighscore = PlayerPrefs.GetInt(“highscore”, 0);
if(newHighscore > oldHighscore)
PlayerPrefs.SetInt(“highscore”, newHighscore);
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class highScore : MonoBehaviour {

public Text counterText;
int highScoreText;
// Use this for initialization
void Start () {

highScoreText = PlayerPrefs.GetInt(“highscore”, 0);
counterText = GetComponent<Text>() as Text;
counterText.text = highScoreText.ToString(“00”);
}
}

css.php