Wednesday, 26 March 2014
Fences
I have now added wooden fences along the path around the game level to help guide the player. I did this due to feedback on my game during the demo day. Many found it difficult to stick to the path due to the visibility of the path and the indifferent terrain throughout. I have tested the new paths with the fence and this problem has now been rectified.
Starting area boundaries
Due to feedback from the demo day of my game, I have added in rocks the guide the player towards the path as shown:
Monday, 24 March 2014
Saturday, 22 March 2014
House interior images
Below are images of the interior of the in game house showing the hallway and all six rooms. I was planning to do a video walk through but the game play was lagging so I decided not to just for now.
![]() |
Hallway |
![]() |
Room 1 with overturned chair and table |
![]() |
Room 2 with a table, chair and two collectables |
![]() |
Room 3 with a lamp, chest of drawers and another collectable |
![]() |
Room 4 with bloodstained bed and a lamp |
![]() |
Room 5 with bed blocking doorway |
![]() |
Room 6 with an 'operating table' a saw and a blood stained floor |
3Ds Max house
I made one of the main assests of the game using 3Ds Max. This was my first time using this software so hopefully it turned out o.k.
Creation of the house:
Creation of the house:
More updates to come
I will be uploading more content to this blog about the games progress, this will including picture and/ or video content of the game.
Xbox removal
I have decided to remove the Xbox controller and revert back to keyboard and mouse.I have done this because I am constantly changing from a Windows system to a Mac system. Due to the fact that the mapping of the controller changes for each system it results in issues.
Collectable (same for all collectables with different variable names)
public class Collectable2 : MonoBehaviour {
public GameObject Collectable;
public float Distance = 5.0f;
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.CollectablePoints += 100;
Destroy (gameObject);
HUD.PickUpTextCollectable2 = "";
}
}
void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Vector3.Distance (playerPos, transform.position) <= Distance)
{
HUD.PickUpTextCollectable2 = "Left Click To Pick Up Book";
}
else
{
HUD.PickUpTextCollectable2 = "";
}
}
}
public GameObject Collectable;
public float Distance = 5.0f;
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.CollectablePoints += 100;
Destroy (gameObject);
HUD.PickUpTextCollectable2 = "";
}
}
void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Vector3.Distance (playerPos, transform.position) <= Distance)
{
HUD.PickUpTextCollectable2 = "Left Click To Pick Up Book";
}
else
{
HUD.PickUpTextCollectable2 = "";
}
}
}
Enemy movement due to player interaction
public class WindowWalker : MonoBehaviour {
public AudioClip HeartBeat;
// this is an object, so that you can move it around in the editor.
public Transform target;
public GameObject collect;
//public GameObject enemy;
// units per second
public float speed = 3;
//void Start()
//{
// gameObject.renderer.enabled = false;
//}
void Update(){
//if (collect != false)
//{
// gameObject.renderer.enabled = false;
//}
if (collect != true)
{
audio.PlayOneShot(HeartBeat, 1.0f);
//gameObject.renderer.enabled = true;
//spawn = (GameObject)Instantiate(Resources.Load("DarkEnemy"));
// remember, 10 - 5 is 5, so target - position is always your direction.
Vector3 dir = target.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 = speed * 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);
Destroy(gameObject, 6);
}
}
//public GameObject Battery;
//public GameObject Man;
//public GameObject GameObjectA;
//public GameObject GameObjectB;
// Update is called once per frame
//void Update ()
//{
// if (Battery != true)
// {
// Instantiate(Man);
// MoveObject(GameObjectA, GameObjectB);
// Destroy(Man);
// }
//}
}
public AudioClip HeartBeat;
// this is an object, so that you can move it around in the editor.
public Transform target;
public GameObject collect;
//public GameObject enemy;
// units per second
public float speed = 3;
//void Start()
//{
// gameObject.renderer.enabled = false;
//}
void Update(){
//if (collect != false)
//{
// gameObject.renderer.enabled = false;
//}
if (collect != true)
{
audio.PlayOneShot(HeartBeat, 1.0f);
//gameObject.renderer.enabled = true;
//spawn = (GameObject)Instantiate(Resources.Load("DarkEnemy"));
// remember, 10 - 5 is 5, so target - position is always your direction.
Vector3 dir = target.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 = speed * 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);
Destroy(gameObject, 6);
}
}
//public GameObject Battery;
//public GameObject Man;
//public GameObject GameObjectA;
//public GameObject GameObjectB;
// Update is called once per frame
//void Update ()
//{
// if (Battery != true)
// {
// Instantiate(Man);
// MoveObject(GameObjectA, GameObjectB);
// Destroy(Man);
// }
//}
}
Well sound effect
public class WellSound : MonoBehaviour {
public AudioClip HeartSound;
void OnTriggerEnter (Collider Well)
{
if (Well.tag == "Player" ) {
audio.PlayOneShot(HeartSound, 1.0f);
}
}
}
public AudioClip HeartSound;
void OnTriggerEnter (Collider Well)
{
if (Well.tag == "Player" ) {
audio.PlayOneShot(HeartSound, 1.0f);
}
}
}
Battery sound effect
public class HouseBatteryPickUpSound : MonoBehaviour {
public AudioClip heartBeat;
void OnTriggerEnter(Collider Player)
{
if (Player.tag == "Battery")
{
audio.PlayOneShot(heartBeat, 1.0f);
}
}
}
public AudioClip heartBeat;
void OnTriggerEnter(Collider Player)
{
if (Player.tag == "Battery")
{
audio.PlayOneShot(heartBeat, 1.0f);
}
}
}
Helicopter blade spin
public class HelicopterBladeSpin : MonoBehaviour {
// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up * 30);
}
}
// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up * 30);
}
}
Graveyard sound effect
public class GraveyardSound : MonoBehaviour {
public AudioClip graveYard;
// Update is called once per frame
void OnTriggerEnter(Collider Player)
{
if (Player.tag == "Graveyard")
{
audio.PlayOneShot(graveYard, 1.0f);
}
}
void OnTriggerExit (Collider Player)
{
if (Player.tag == "Graveyard")
{
audio.PlayOneShot(graveYard, 0.0f);
}
}
}
public AudioClip graveYard;
// Update is called once per frame
void OnTriggerEnter(Collider Player)
{
if (Player.tag == "Graveyard")
{
audio.PlayOneShot(graveYard, 1.0f);
}
}
void OnTriggerExit (Collider Player)
{
if (Player.tag == "Graveyard")
{
audio.PlayOneShot(graveYard, 0.0f);
}
}
}
Flashlight spawn
public class FlashlightSpawn : MonoBehaviour {
void Start()
{
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
GameObject spawn = (GameObject)Instantiate(Resources.Load("Flashlight"));
spawn.transform.position = new Vector3(x, y, 0);
}
}
}
}
void Start()
{
for (int y = 0; y < 5; y++) {
for (int x = 0; x < 5; x++) {
GameObject spawn = (GameObject)Instantiate(Resources.Load("Flashlight"));
spawn.transform.position = new Vector3(x, y, 0);
}
}
}
}
Enabling flare (not currently in use but does work)
//public class FlareEnable : MonoBehaviour {
//
// public static float lightFlareLife = 49;
// public AudioClip soundEffect;
// public Light lightFlare;
// public float flareReductionSpeed = 3.0f;
// public AudioClip soundEffect2;
//
// void Awake()
// {
// lightFlare.enabled = false;
// }
//
// void Update()
// {
// if (HUD.FlareCount > 0)
// {
// lightFlareLife = lightFlareLife - (flareReductionSpeed * Time.deltaTime);
//
// }
//
// if (Input.GetButtonDown ("LeftBumper") && HUD.FlareCount > 0 && !lightFlare.enabled)
// {
// audio.PlayOneShot(soundEffect, 1.0f);
// audio.PlayOneShot(soundEffect2, 1.0f);
//
// if (lightFlareLife <= 0 && HUD.FlareCount > 0)
// {
// lightFlareLife = 0;
// HUD.FlareCount--;
// lightFlareLife = 49;
// }
// lightFlare.enabled = true;
//
// }
//
//
// if (lightFlareLife <= 0)
// {
// lightFlareLife = 0;
// lightFlare.enabled = false;
// }
// }
//}
//
// public static float lightFlareLife = 49;
// public AudioClip soundEffect;
// public Light lightFlare;
// public float flareReductionSpeed = 3.0f;
// public AudioClip soundEffect2;
//
// void Awake()
// {
// lightFlare.enabled = false;
// }
//
// void Update()
// {
// if (HUD.FlareCount > 0)
// {
// lightFlareLife = lightFlareLife - (flareReductionSpeed * Time.deltaTime);
//
// }
//
// if (Input.GetButtonDown ("LeftBumper") && HUD.FlareCount > 0 && !lightFlare.enabled)
// {
// audio.PlayOneShot(soundEffect, 1.0f);
// audio.PlayOneShot(soundEffect2, 1.0f);
//
// if (lightFlareLife <= 0 && HUD.FlareCount > 0)
// {
// lightFlareLife = 0;
// HUD.FlareCount--;
// lightFlareLife = 49;
// }
// lightFlare.enabled = true;
//
// }
//
//
// if (lightFlareLife <= 0)
// {
// lightFlareLife = 0;
// lightFlare.enabled = false;
// }
// }
//}
Enemy spawn
public class enemyVillageSpawn : MonoBehaviour {
//public AudioClip HeartBeat;
public GameObject spawnPoint;
public GameObject collect;
void Update(){
if (collect != true)
{
//audio.PlayOneShot(HeartBeat, 1.0f);
GameObject spawn = (GameObject)Instantiate(Resources.Load("DarkEnemy1"));
Debug.Log("I HAVE SPAWNED");
}
}
}
//public AudioClip HeartBeat;
public GameObject spawnPoint;
public GameObject collect;
void Update(){
if (collect != true)
{
//audio.PlayOneShot(HeartBeat, 1.0f);
GameObject spawn = (GameObject)Instantiate(Resources.Load("DarkEnemy1"));
Debug.Log("I HAVE SPAWNED");
}
}
}
Enemy following player
public class EnemyFollow : MonoBehaviour {
public Transform target; //will show in inspecter but dont need to fill in
public int moveSpeed;
public int rotationSpeed;
public int maxdistance; //if player within this distance in inspector it will follow is not it will not follow
private Transform myTransform;
public AudioClip approachHeartBeat; //this is sound effect dont need
void Start(){
myTransform = transform;
target = GameObject.FindGameObjectWithTag ("Player").transform;//will find object tagged Player
}
void Update () {
if (Vector3.Distance(target.position, myTransform.position) < maxdistance)
{
//Debug.Log ("I AM FUCKING MOVING");
audio.PlayOneShot(approachHeartBeat, 1.0f); //this is sound effect dont need
// Get a direction vector from us to the target
Vector3 dir = target.position - myTransform.position;
// Normalize it so that it's a unit direction vector
dir.Normalize();
// Move ourselves in that direction
transform.position += dir * moveSpeed * Time.deltaTime;
}
if (Vector3.Distance (target.position, myTransform.position) > maxdistance)
{
Destroy(gameObject);
}
}
}
public Transform target; //will show in inspecter but dont need to fill in
public int moveSpeed;
public int rotationSpeed;
public int maxdistance; //if player within this distance in inspector it will follow is not it will not follow
private Transform myTransform;
public AudioClip approachHeartBeat; //this is sound effect dont need
void Start(){
myTransform = transform;
target = GameObject.FindGameObjectWithTag ("Player").transform;//will find object tagged Player
}
void Update () {
if (Vector3.Distance(target.position, myTransform.position) < maxdistance)
{
//Debug.Log ("I AM FUCKING MOVING");
audio.PlayOneShot(approachHeartBeat, 1.0f); //this is sound effect dont need
// Get a direction vector from us to the target
Vector3 dir = target.position - myTransform.position;
// Normalize it so that it's a unit direction vector
dir.Normalize();
// Move ourselves in that direction
transform.position += dir * moveSpeed * Time.deltaTime;
}
if (Vector3.Distance (target.position, myTransform.position) > maxdistance)
{
Destroy(gameObject);
}
}
}
Flashlight pick up
public class pickUpClick : MonoBehaviour {
//public GameObject SpawnPoint;
public enum Item
{
Flashlight,
}
public float Distance = 5.0f;
public Item item;
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.HasFlashlight = true;
Destroy (gameObject);
HUD.PickUpTextTorch = "";
//Instantiate(Resources.Load("Flashlight"));//, gameObject.transform.position = playerPos);
//gameObject.transform.position = playerPos;
//SpawnPoint = (GameObject)Instantiate(Resources.Load("Flashlight"));
}
}
void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Vector3.Distance (playerPos, transform.position) <= Distance )// && HUD.HasFlashlight == false
{
HUD.PickUpTextTorch = "Left Click To Pick Up Flashlight";
}
else
{
HUD.PickUpTextTorch = "";
}
}
// public AudioClip flashlightSound;
// public AudioClip batterySound;
//
// void OnMouseDown()
// {
// var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
//
// if(Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
// {
// if(item == Item.Flashlight)
// {
// Flashlight.HeadLightMount.SetActiveRecursively(true);
// Flashlight.HeadLightMount.active = true;
//
// AudioSource.PlayClipAtPoint(flashlightSound, transform.position, 1);
//
// HUD.HasFlashlight = true;
// }
// else
// HUD.BatteryCount++;
//
// AudioSource.PlayClipAtPoint(batterySound, transform.position, 1);
//
// Destroy(gameObject);
// }
// }
}
//public GameObject SpawnPoint;
public enum Item
{
Flashlight,
}
public float Distance = 5.0f;
public Item item;
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.HasFlashlight = true;
Destroy (gameObject);
HUD.PickUpTextTorch = "";
//Instantiate(Resources.Load("Flashlight"));//, gameObject.transform.position = playerPos);
//gameObject.transform.position = playerPos;
//SpawnPoint = (GameObject)Instantiate(Resources.Load("Flashlight"));
}
}
void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Vector3.Distance (playerPos, transform.position) <= Distance )// && HUD.HasFlashlight == false
{
HUD.PickUpTextTorch = "Left Click To Pick Up Flashlight";
}
else
{
HUD.PickUpTextTorch = "";
}
}
// public AudioClip flashlightSound;
// public AudioClip batterySound;
//
// void OnMouseDown()
// {
// var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
//
// if(Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
// {
// if(item == Item.Flashlight)
// {
// Flashlight.HeadLightMount.SetActiveRecursively(true);
// Flashlight.HeadLightMount.active = true;
//
// AudioSource.PlayClipAtPoint(flashlightSound, transform.position, 1);
//
// HUD.HasFlashlight = true;
// }
// else
// HUD.BatteryCount++;
//
// AudioSource.PlayClipAtPoint(batterySound, transform.position, 1);
//
// Destroy(gameObject);
// }
// }
}
HUD
public class HUD : MonoBehaviour
{
public static double CollectablePoints;
public static string PickUpTextTorch;
//public static int FlareCount;
public static int BatteryCount;
public static bool HasFlashlight;
//public static string PickUpTextFlare;
public static string PickUpTextCollectable1;
public static string PickUpTextCollectable2;
public static string PickUpTextCollectable3;
public static string PickUpTextCollectable4;
public static string PickUpTextCollectable5;
public static string PickUpTextCollectable6;
public static string PickUpTextCollectable7;
public static string PickUpTextBattery;
public void OnGUI()
{
if (HasFlashlight)
{
GUI.Label (new Rect (10, 10, 80, 30), "Flashlight");
GUI.Label (new Rect (70, 10, 80, 30), Flashlight.BatteryLife.ToString ("F2"));
}
GUI.Label (new Rect (10, 40, 80, 30), "Batteries");
GUI.Label (new Rect (70, 40, 80, 30), BatteryCount.ToString ());
//GUI.Label (new Rect (10, 55, 80, 30), "Flares");
//GUI.Label (new Rect (70, 55, 80, 30), FlareCount.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextTorch.ToString ());
GUI.Label (new Rect (10, 65, 80, 30), "Points");
GUI.Label (new Rect (70, 65, 80, 30), CollectablePoints.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable1.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable2.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable3.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable4.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable5.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable6.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable7.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextBattery.ToString ());
//GUI.Label (new Rect (700, 1000, 200, 30), "");
//GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextFlare.ToString ());
}
}
{
public static double CollectablePoints;
public static string PickUpTextTorch;
//public static int FlareCount;
public static int BatteryCount;
public static bool HasFlashlight;
//public static string PickUpTextFlare;
public static string PickUpTextCollectable1;
public static string PickUpTextCollectable2;
public static string PickUpTextCollectable3;
public static string PickUpTextCollectable4;
public static string PickUpTextCollectable5;
public static string PickUpTextCollectable6;
public static string PickUpTextCollectable7;
public static string PickUpTextBattery;
public void OnGUI()
{
if (HasFlashlight)
{
GUI.Label (new Rect (10, 10, 80, 30), "Flashlight");
GUI.Label (new Rect (70, 10, 80, 30), Flashlight.BatteryLife.ToString ("F2"));
}
GUI.Label (new Rect (10, 40, 80, 30), "Batteries");
GUI.Label (new Rect (70, 40, 80, 30), BatteryCount.ToString ());
//GUI.Label (new Rect (10, 55, 80, 30), "Flares");
//GUI.Label (new Rect (70, 55, 80, 30), FlareCount.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextTorch.ToString ());
GUI.Label (new Rect (10, 65, 80, 30), "Points");
GUI.Label (new Rect (70, 65, 80, 30), CollectablePoints.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable1.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable2.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable3.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable4.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable5.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable6.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextCollectable7.ToString ());
GUI.Label (new Rect (700, 1000, 200, 30), "");
GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextBattery.ToString ());
//GUI.Label (new Rect (700, 1000, 200, 30), "");
//GUI.Label (new Rect (700, 1000, 200, 30), PickUpTextFlare.ToString ());
}
}
Battery pick up
public class HouseBatteryPickUp : MonoBehaviour {
public float Distance = 5.0f;
public GameObject Battery;
// void OnTriggerEnter(Collider other)
// {
// if (other.tag == "Player") { //&& Input.GetButtonDown("xButton") == true)
// HUD.HasFlashlight = true;
// Destroy (gameObject);
// }
//
//
// }
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.BatteryCount++;
Destroy(gameObject);
HUD.PickUpTextBattery = "";
}
}
void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Vector3.Distance (playerPos, transform.position) <= Distance)
{
HUD.PickUpTextBattery = "Left Click To Pick Up Battery";
}
else
{
HUD.PickUpTextBattery = "";
}
}
}
public float Distance = 5.0f;
public GameObject Battery;
// void OnTriggerEnter(Collider other)
// {
// if (other.tag == "Player") { //&& Input.GetButtonDown("xButton") == true)
// HUD.HasFlashlight = true;
// Destroy (gameObject);
// }
//
//
// }
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.BatteryCount++;
Destroy(gameObject);
HUD.PickUpTextBattery = "";
}
}
void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
if (Vector3.Distance (playerPos, transform.position) <= Distance)
{
HUD.PickUpTextBattery = "Left Click To Pick Up Battery";
}
else
{
HUD.PickUpTextBattery = "";
}
}
}
Flashlight script
public class Flashlight : MonoBehaviour {
public static float BatteryLife = 100;
public AudioClip soundEffect;
public Light Torch;
public float BatteryReductionSpeed = 3.0f;
void Awake()
{
Torch.enabled = false;
}
void Update()
{
if (Torch.enabled)
{
BatteryLife = BatteryLife - (BatteryReductionSpeed * Time.deltaTime);
}
if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && !Torch.enabled)
{
audio.PlayOneShot(soundEffect, 1.0f);
if (BatteryLife <= 0 && HUD.BatteryCount>0)
{
HUD.BatteryCount--;
BatteryLife = 100;
}
Torch.enabled = true;
}
else if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && Torch.enabled)
{
audio.PlayOneShot(soundEffect, 1.0f);
Torch.enabled = false;
}
if (BatteryLife <= 0)
{
BatteryLife = 0;
Torch.enabled = false;
}
}
}
public static float BatteryLife = 100;
public AudioClip soundEffect;
public Light Torch;
public float BatteryReductionSpeed = 3.0f;
void Awake()
{
Torch.enabled = false;
}
void Update()
{
if (Torch.enabled)
{
BatteryLife = BatteryLife - (BatteryReductionSpeed * Time.deltaTime);
}
if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && !Torch.enabled)
{
audio.PlayOneShot(soundEffect, 1.0f);
if (BatteryLife <= 0 && HUD.BatteryCount>0)
{
HUD.BatteryCount--;
BatteryLife = 100;
}
Torch.enabled = true;
}
else if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && Torch.enabled)
{
audio.PlayOneShot(soundEffect, 1.0f);
Torch.enabled = false;
}
if (BatteryLife <= 0)
{
BatteryLife = 0;
Torch.enabled = false;
}
}
}
Updating scripts
I will now be uploading all scripts that I am currently using, this does not include scripts I have made but are not in use. I have also kept the comments in but these are mostly failed attempts of what I was trying to accomplish, this is for future reference.
Tuesday, 4 March 2014
Xbox 360 Controller Mapping
I have now changed the controls so they work on a Xbox 360 controller. To do this is used the input directory in unity under edit>project setting>input. I changed the names of the controls and buttons in this to match the controller mapping. I used the following site for the names of the controllers buttons for unity. I then changed the code that needed to be changed to get this to work, however for the first person controls on the analogue sticks I had to change no code as the names were fine and worked as expected. One problem I had was that the right analogue stick looking control moved continuously when the stick was moved, to fix this I had to add some 'Dead' to it.
Code changes
The past three coding posts that were uploaded may change. I may change the code in some or all of these scripts to improve the gameplay and make it more efficient. As of now this code is being used to get the basic mechanics of the game working as expected. If I do change any of these scripts I will upload the new code and state what changes have been made.
Flashlight Code
Below is the code for the flashlight, it does the following:
- Upon spawn the player will not have a flashlight
- When a flashlight is collected it will be off until it is turned on
- if the player has a torch and it is on reduce the battery life
- if the right bumper (xbox controller) is pressed the light will turn on if it not
- likewise if the right bumper button is pressed when the flashlight is on, it will turn off
- when the flashlight is collected the HUD for the battery life will be set to 100
- if the battery life is less than or equal to 0 set it to zero and turn the flashlight off
- if the battery life is 0 and the HUD shows that batteries are held reduce the battery count by one and add 100 to the battery life (for the flashlight)
using UnityEngine;
using System.Collections;
public class Flashlight : MonoBehaviour {
public static float BatteryLife = 100;
public Light Torch;
public float BatteryReductionSpeed = 3.0f;
void Awake()
{
Torch.enabled = false;
}
void Update()
{
if (Torch.enabled)
{
BatteryLife = BatteryLife - (BatteryReductionSpeed * Time.deltaTime);
}
if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && !Torch.enabled)
{
if (BatteryLife <= 0 && HUD.BatteryCount>0)
{
HUD.BatteryCount--;
BatteryLife = 100;
}
Torch.enabled = true;
}
else if (Input.GetButtonDown ("RightBumper") && HUD.HasFlashlight && Torch.enabled)
{
Torch.enabled = false;
}
if (BatteryLife <= 0)
{
BatteryLife = 0;
Torch.enabled = false;
}
}
}
Pick Up code
Below is the code for the picking up of the objects such as the torch and batteries. The code for the battery pick up isn't complete yet as there are no batteries in the scene as of yet. The game object i.e the flashlight will be destroyed (taken off the scene) when it has been picked up, as shown in this code. As of yet the object will be picked up when it is simply walked into, I want to improve this so the player is prompted with a button to press to pick up objects.
using UnityEngine;
using System.Collections;
public class PickUp : MonoBehaviour {
public enum Item
{
Flashlight,
Battery
}
public Item item;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
HUD.HasFlashlight = true;
Destroy(gameObject);
}
//else
//HUD.BatteryCount++;
//Destroy (gameObject);
}
}
using UnityEngine;
using System.Collections;
public class PickUp : MonoBehaviour {
public enum Item
{
Flashlight,
Battery
}
public Item item;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
HUD.HasFlashlight = true;
Destroy(gameObject);
}
//else
//HUD.BatteryCount++;
//Destroy (gameObject);
}
}
Flashlight HUD
Below is the C# sharp code I used to create the HUD for the flashlight. This code will display the flashlights remaining power out of 100, which will only show when a flashlight is collected, and below the number of batteries held will be shown:
using UnityEngine;
using System.Collections;
public class HUD : MonoBehaviour
{
public static int BatteryCount;
public static bool HasFlashlight;
void OnGUI()
{
if (HasFlashlight)
{
GUI.Label (new Rect (10, 10, 80, 30), "Flashlight");
GUI.Label (new Rect (70, 10, 80, 30), Flashlight.BatteryLife.ToString ("F2"));
}
GUI.Label (new Rect (10, 40, 80, 30), "Batteries");
GUI.Label (new Rect (70, 40, 80, 30), BatteryCount.ToString ());
}
}
using UnityEngine;
using System.Collections;
public class HUD : MonoBehaviour
{
public static int BatteryCount;
public static bool HasFlashlight;
void OnGUI()
{
if (HasFlashlight)
{
GUI.Label (new Rect (10, 10, 80, 30), "Flashlight");
GUI.Label (new Rect (70, 10, 80, 30), Flashlight.BatteryLife.ToString ("F2"));
}
GUI.Label (new Rect (10, 40, 80, 30), "Batteries");
GUI.Label (new Rect (70, 40, 80, 30), BatteryCount.ToString ());
}
}
Subscribe to:
Posts (Atom)