22 January 2015

Games Mechanic - State of the Game address.

Since the last scripting update, a few things have been updated. The main body of text is below, hidden using a readmore for the sake of blog readability.




function OnTriggerEnter ( col : Collider)
{
Application.LoadLevel ("Test");
}

This script is placed on the reward chest and transports the player back to the main hub, initially called test and due to the fact that it has been referred to in numerous scripts shall have to remain unless either myself or Ollie feel like trawling the other scripts and replacing the level names with the integers assigned to them by Unity. A variation on this handles the transition to the map screen, moving to the layer "Map."

#pragma strict
public var Sword : GameObject;
public var enemyhealth : int = 10;
public var Target : GameObject;
public var Chest : GameObject;
public var ChestLid : GameObject;
var chestopened : boolean = false;

function OnTriggerEnter (Sword : Collider)
{
if (Sword.tag == "Weapon")
{
enemyhealth --;
Sword.tag = "None";
}
}
function Update () 
{
Target = GameObject.Find("Player(Clone)");
GetComponent(NavMeshAgent).destination = Target.transform.position;

if (enemyhealth == 0 && chestopened == false)
{
transform.position.y = -100;
GetComponent(NavMeshAgent) .enabled = false;
Chest.renderer.enabled = true;
Chest.collider.enabled = true;
ChestLid.renderer.enabled = true;
ChestLid.collider.enabled = true;
Chest.animation.Play("Chest_Open");
chestopened = true;
}
}

The enemy health script as it currently stands. The main changes include a line to find the player in the scene, and a few lines dealing with creating and moving the reward chest once the enemy is dead.

#pragma strict
function OnMouseOver ()
{
renderer.material.color = Color.red;
if(Input.GetButtonDown ("Fire1"))
{
Application.LoadLevelAsync ("Target");
}
}
function OnMouseExit () 
{
renderer.material.color = Color.blue;
}
A script used in the map screen, which handles moving from this scene to the relevant arena. Mouseclicks were surprisingly easy to deal with.

#pragma strict
var spawnpoint : GameObject;
var player : GameObject;
var playerCamera : GameObject;
function Awake ()
{
DontDestroyOnLoad (transform.gameObject);
player = GameObject.Find("Player(Clone)");
spawnpoint = GameObject.Find("Spawn");
player.transform.position = spawnpoint.transform.position;
playerCamera.SetActive(false);
}
function OnLevelWasLoaded (level : int)
{
if (level == 0) 
{
spawnpoint = GameObject.Find("Spawn");
player.transform.position = spawnpoint.transform.position;
playerCamera.SetActive(false);
}
if (level == 1) 
{
spawnpoint = GameObject.Find("Spawn");
player.transform.position = spawnpoint.transform.position;
playerCamera.SetActive(true);
}
if (level == 2) 
{
spawnpoint = GameObject.Find("Spawn");
player.transform.position = spawnpoint.transform.position;
playerCamera.SetActive(true);
}
}
A script that deals with moving the player to a specified location in all the individual levels in the current state of the game.