29 January 2015

Games Mechanic, Weapon Swapping

#pragma strict

public var Sword :GameObject;
public var normal : GameObject;
public var Advnce : GameObject;

var Click : boolean;
var Swing : boolean;

function Start()
{
animation.Play("Idle");
Swing = false;
Click = false;
Sword.tag = "None";
}

function Update() 
{
if(Input.GetMouseButtonDown(0)&&Swing == false)
{
SwordSwing();
}

if(Input.GetMouseButtonDown (1)&&Click == false &&!animation.IsPlaying("Stab"))
{
Debug.Log ("Pressed RMB");
Weaponswap();
}

}

function SwordSwing()
{
Swing = true;
Sword.tag ="Weapon";
animation.Play("Stab", PlayMode.StopAll);
yield WaitForSeconds (1);
Sword.tag = "None";
Swing = false;
}

function Weaponswap()
{
Click = true;

Advnce.renderer.enabled = !Advnce.renderer.enabled;
normal.renderer.enabled = !normal.renderer.enabled;
Click = false;
}


Big addition to the weapon swinging script, additions are in blue, What these additions do is swap the visuals of the weapon the player is holding on a right click. Whilst purely a visual effect as is, later iterations will add in more functionality like higher damaging weaponry.

Also I made this sword and rack.
Just a piece of window dressing right now, but I intend to incorporate this as a form of inventory, where weapons will be placed in the hub scene when not in use.

No comments:

Post a Comment