Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Tuesday, 6 May 2014

Steampunk: Building The Game

I have made the build for the final game which will be on the hand-in CD this file contains three scenes 0 is the main menu 1 one is the steam punk world with the normal character controller unit and number 2 is the same environment but with an oculus rift character controller both of fees scenes are accessible through the main menu screen which has been updated below and now contains code that allows the player to choose each environment and when in the environment have no mouse visible onscreen and be able to exit the game by simply pressing escape.


i have also made a icon file for the game which you can see below this is an icon file and can be added as shown below.









this was not a need asset in the final game I just thought it would be a nice touch to the game folder by having this icon over it instead of the normal default file picture as you can see below this is implemented on the actual physical steam game folder with the EXE and the data file inside of it.








Below are the three code scripts that allow what I discussed above to function in the game

// This simple script below centres the mouse cursor and also makes it invisible in the game build which helps immerse the player instead of having a mouse pointer hovering in the centre of the screen

#pragma strict

function Start () {
Screen.lockCursor = true;
}

function Update()
{

}

also when the mouse is invisible which this code above has inflicted on the game it is now impossible to escape again without doing control alt delete sub by adding this simple code below where you press escape it the game will exit

using UnityEngine;
using System.Collections;

public class Escape : MonoBehaviour {




// Use this for initialization
void Start () {

}

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

if(Input.GetKeyDown (KeyCode.Escape))
  {
Application.Quit ();
}
}


}

below is the main manu script that allows the play the normal game the play the oculus and exit the game using this code below

var isQuit=false;

function OnMouseEnter(){
//change text color
renderer.material.color=Color.red;
}

function OnMouseExit(){
//change text color
renderer.material.color=Color.white;
}

function OnMouseUp(){

if(this.gameObject.name=="GUIPlay")
{
Application.LoadLevel(1);
}

if(this.gameObject.name=="GUIPlayOcc")
{
Application.LoadLevel(2);
}

if(this.gameObject.name=="GUIExit")
{
Application.Quit();
}
}

Monday, 5 May 2014

Steampunk: Game Menu (Update)

Here i have been flowing atutorial on how to make a game menu following this step-by-step videoand using the code provided below I use this and implemented it in my main menu for the game environment in his he only has two start and except but from my ninth hoping to add a fly through option which will allow the player to be on a fixed path and see parts of the environment he would not probably find  by themselves.


and also using the code below in the game menu

var isQuit=false;

function OnMouseEnter(){
//change text color
renderer.material.color=Color.red;
}

function OnMouseExit(){
//change text color
renderer.material.color=Color.white;
}

function OnMouseUp(){
//is this quit
if (isQuit==true) {
//quit the game
Application.Quit();
}
else {
//load level
Application.LoadLevel(1);
}
}

function Update(){
//quit game if escape key is pressed
if (Input.GetKey(KeyCode.Escape)) { Application.Quit();
}
}

with this code the text colour will change as the mouse hangs over it as u can see in the pictures below.


Wednesday, 9 October 2013

Steampunk Scripting

Here I was looking for some simple code to run animations on mouse down I found it in the book that I had brught myself below.



















But also i looked at the code from a guy called Edithson Abelard who dose tutorals for maya into unity. there is a link and video below.

http://www.youtube.com/watch?v=PvmMyMklwyo


Using this simple code as shown blow I will be able to run animations in unity from a click of a buttom.

#pragma strict
var doorObj:GameObject;
var isOpen = false;

var timeBeforeNextAnimation :float = 0;

function OnMouseDown(){
 Debug.Log("mouse is down");

 if( timeBeforeNextAnimation < Time.time )
 {
  if(!this.isOpen){
   doorObj.animation.Play("open");
   this.isOpen = true;
  }else{
   doorObj.animation.Play("close");
   this.isOpen = false;
  }

  timeBeforeNextAnimation = Time.time + 3;

 }
}

function Start () {
}
function Update () {
}