Skip to content

Commit

Permalink
Added scripting to all of the various objects. Added a little UI to
Browse files Browse the repository at this point in the history
allow player interaction with objects using script-to-script
interaction.  Moved functionality around to said object scripts to give
the underlying objects their game-related functionality.
  • Loading branch information
Alex Morais committed Nov 22, 2012
1 parent 74d1438 commit 95c5025
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 200 deletions.
Binary file modified Assets/Base.prefab
Binary file not shown.
Binary file modified Assets/Branch.prefab
Binary file not shown.
Binary file modified Assets/BranchBush.prefab
Binary file not shown.
Binary file modified Assets/Brancher.prefab
Binary file not shown.
102 changes: 67 additions & 35 deletions Assets/CamControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ private var originalColorOfSelected : Color;
public var targetedSelection : GameObject; // hold Fire2-selected
private var originalColorOfTargeted : Color;

function Start () {
function Start ()
{
gameObject.Find("Main Camera").transform.position = camOrigin.transform.position;
gameObject.Find("Main Camera").transform.position.y = camHeight;
}

function Update () {
function Update ()
{

var camPos : Vector3 = gameObject.Find("Main Camera").transform.position;

Expand All @@ -32,52 +34,81 @@ function Update () {
camPos.x = Mathf.Clamp(camPos.x + Input.GetAxis("Mouse X"), posMin, posMax);
camPos.z = Mathf.Clamp(camPos.z + Input.GetAxis("Mouse Y"), posMin, posMax);
}
else

DoMousePicking();

gameObject.Find("Main Camera").transform.position = camPos;
}

function OnGUI()
{
if(null != currentSelection)
{
/* Mouse Picking */
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
var layerMask : LayerMask = -1;

if(Input.GetButtonDown("Fire1"))
{
Debug.Log("Fire1 pressed");
layerMask = 1 << LayerMask.NameToLayer("Forkers") |
1 << LayerMask.NameToLayer("Branchers") |
1 << LayerMask.NameToLayer("Buildings");

// Check if we hit a selectable object like a unit or building
if(Physics.Raycast(ray, hit, Mathf.Infinity, layerMask))
{
SelectObject(GameObject.Find(hit.transform.name));
}
if(currentSelection.name.Contains("Base"))
{
currentSelection.GetComponent(BaseScript).DoSelectedGUI(GetSelectedGUIRect());
}

if((null != currentSelection) && (Input.GetButtonUp("Fire2")))
else if((currentSelection.name.Contains("forker")) ||
(currentSelection.name.Contains("brancher")))
{
Debug.Log("Fire2 pressed");
layerMask = 1 << LayerMask.NameToLayer("Selectable") |
1 << LayerMask.NameToLayer("Trees") |
1 << LayerMask.NameToLayer("Buildings");

// Operate on targetedSelection accordingly
if(Physics.Raycast(ray, hit, Mathf.Infinity, layerMask))
{
TargetObject(GameObject.Find(hit.transform.name));
}
currentSelection.GetComponent(UnitScript).DoSelectedGUI(GetSelectedGUIRect());
}
else
{
Debug.Log("No patterns matched for currentSelected in OnGUI.");
}
}
}

function GetSelectedGUIRect()
{
return Rect(Screen.width*0.75, Screen.height*0.7, Screen.width*0.25, Screen.height*0.2);
}

function DoMousePicking()
{
/* Mouse Picking */
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
var layerMask : LayerMask = -1;

gameObject.Find("Main Camera").transform.position = camPos;
if(Input.GetButtonDown("Fire1"))
{
//Debug.Log("Fire1 pressed");
layerMask = 1 << LayerMask.NameToLayer("Forkers") |
1 << LayerMask.NameToLayer("Branchers") |
1 << LayerMask.NameToLayer("Buildings");

// Check if we hit a selectable object like a unit or building
if(Physics.Raycast(ray, hit, Mathf.Infinity, layerMask))
{
//SelectObject(GameObject.Find(hit.transform.name));
SelectObject(hit.transform.gameObject);
}
}

if((null != currentSelection) && (Input.GetButtonUp("Fire2")))
{
//Debug.Log("Fire2 pressed");
layerMask = 1 << LayerMask.NameToLayer("Selectable") |
1 << LayerMask.NameToLayer("Trees") |
1 << LayerMask.NameToLayer("Buildings");

// Operate on targetedSelection accordingly
if(Physics.Raycast(ray, hit, Mathf.Infinity, layerMask))
{
//TargetObject(GameObject.Find(hit.transform.name));
TargetObject(hit.transform.gameObject);
}
}
}

function ClearCurrentSelection()
{
if(null != currentSelection)
{
currentSelection.renderer.material.color = originalColorOfSelected;

//TODO: Use a selected mat
currentSelection = null;
}
}

Expand All @@ -86,6 +117,7 @@ function ClearCurrentTargeted()
if(null != targetedSelection)
{
targetedSelection.renderer.material.color = originalColorOfTargeted;
targetedSelection = null;
}
}

Expand Down
Binary file modified Assets/Fork.prefab
Binary file not shown.
Binary file modified Assets/Forker.prefab
Binary file not shown.
23 changes: 0 additions & 23 deletions Assets/ForkerScript.js

This file was deleted.

Binary file modified Assets/Fortification.prefab
Binary file not shown.
Loading

0 comments on commit 95c5025

Please sign in to comment.