Thank you ahead of time for any responses regardless of the outcome.
So I just got through watching some videos, reading some books. All in regards to Unity and Javascript. I jumped in blender made a quick dungeon and some models. Now I get into Unity import my stuff. Throw a character together and start writing its script. Mind you I didn’t plan anything and Im a total noob. Anyways to make a long story short… I’m attempting to make a torch, and that torch’s life burns out X amount of seconds. Well it goes a bit fast. I’ve read about Time.DeltaTime but I cant figure it out. I might be tired or just need to take a break. Anyways if someone could let me know how to limit my “torchLightLife” to seconds and not the speed of light!! I would be thankful. See Code below. Oh and If you see anything else wrong let me know lol. IE stuff I shouldn’t be doing.
#pragma strict
// this is all CharMovement and timing. as well as attacking etc.
//Character Movement variables
var charMove : int;
var charRotate : int;
var moveTime : float;
var rotTime : float;
var allowMove : boolean = true;
//Torch controls variables
var flickerSpeed : float = 0.7;
var torchLightLife : int = 100;
var torchExist : boolean = true;
var randomizer : float;
function Start () {
}
function Update () {
// Movement fwd and back-----------------------------------------------------------------
if (allowMove)
{
if(Input.GetKey("w"))
{
transform.Translate(0,0,charMove);
print("You Take a step foward");
CharacterMove();
}
}
if (allowMove)
{
if(Input.GetKey("s"))
{
transform.Translate(0,0,-charMove);
print("You Take a step back");
CharacterMove();
}
}
// Rotation left and right -------------------------------------------------------------
if (allowMove)
{
if(Input.GetKey("d"))
{
transform.Rotate(0,charRotate,0);
print("You Turn!");
CharactorRot();
}
}
if (allowMove)
{
if(Input.GetKey("a"))
{
transform.Rotate(0,-charRotate,0);
print("You Turn!");
CharactorRot();
}
}
if(torchExist)
{
TorchFlicker();
}
}
// Character move time pause. This basically stops the player from moving to fast.
function CharacterMove()
{
allowMove = false;
yield WaitForSeconds(moveTime);
allowMove = true;
}
// Character rotation pause. This basically stops the player from rotating to fast.
function CharactorRot()
{
allowMove = false;
yield WaitForSeconds(rotTime);
allowMove = true;
}
// This stops the player from clipping through walls. Otherwise with "translate.Transform" i was able to just ignore collision.
// I also had to create a tag "cameraCollision" and set it on said obj.
function OnTriggerEnter (otherObject:Collider)
{
if (otherObject.gameObject.tag == ("cameraCollision"))
{
transform.Translate (0,0,-1);
allowMove = false;
print ("Touched a Collider!");
yield WaitForSeconds(2);
allowMove = true;
}
// start torch trigger pick up.
if (otherObject.gameObject.tag == ("torchPickupItem"))
{
torchLightLife = (Random.Range(500,5000));
torchExist = true;
light.intensity = 2.0;
Destroy(otherObject);
print ("Touched a Collider!");
}
}
// Start Torch controls here.
function TorchFlicker()
{
if (torchExist)
{
light.intensity = 2.0;
}
else light.intensity = 2.0;
randomizer = Random.Range (1.1, 2.1);
light.intensity = randomizer;
yield WaitForSeconds (flickerSpeed);
TorchDeath();
}
function TorchDeath ()
{
if (torchLightLife > 0)
{
yield WaitForSeconds(1);
torchLightLife--;
}
else TorchDie();
}
function TorchDie()
{
if (torchLightLife <= 0)
{
light.intensity = 0;
torchExist = false;
}
}