Thanks zine92, I will look up your script.
What I’m doing now is a mini game for my “storybook apps”. The mini game is about you need to cross to the safety area, theres guard watching. you need to walk when the guard not looking and hide when the guard watching.
So for the guard, I just used 2 texture, one for watching one for not watching. This change of texture will happen randomly between time.
As for now I manage to make what I want(give and take, need more tweeking). What i did is this:
The first code is for walking the character, to walk I just need to push one button and if let got of the button you will stop.
#pragma implicit
#pragma downcast
#pragma strict
var hit : RaycastHit;
var moveSpeed : int;
var character : GameObject;
static var walking : boolean;
function Update ()
{
Walking();
Debug.Log(walking);
}
function Walking()
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButton(0)) //Returns true during the frame the user touches the object
{
if (Physics.Raycast (ray, hit, 100))
{
if(hit.collider.tag == "01")
{
walking = true;
speedToMove = moveSpeed * Time.deltaTime;
character.transform.Translate(Vector3.right * speedToMove, Space.World);
}
else
{
walking = false;
}
}
}
}
Second, the code is to randomly change texture for the guard.
#pragma implicit
#pragma downcast
#pragma strict
var minWait : float;
var maxWait : float;
var minLook : float;
var maxLook: float;
var look : Texture;
var notLook : Texture;
function Update()
{
Guard();
}
function Guard()
{
if(CharacterWalk.walking == true)
{
yield WaitForSeconds(Random.Range(minWait, maxWait));
renderer.material.mainTexture = look;
CharacterWalk.walking = false;
}
if(CharacterWalk.walking == false)
{
yield WaitForSeconds(Random.Range(minLook, maxLook));
renderer.material.mainTexture = notLook;
}
}
manage to do all this, but found a problem. In the first cede, I wrote this one line
else
{
walking = false;
}
it doesnt execute, the bool stuck at “True” doenst return to “False” back. Why is this happening.