Hi everybody ![]()
I’m gonna make a indie game, i’ve made a test game for testing its scripts,
unfortunately i have a problem with my health script,
whenever i die, and i try to load it again its health system remains 0 so it says game over again and again
here is the game with web player format 18 mb click here for download
And i think the problem is with my turret script do damage part
BTW i did this scripts with help of my video tutorial from vtc.
this is my turret script: with javascript:
var target : Transform;
var range = 10.0;
var LeftFlame : GameObject;
var RightFlame : GameObject;
static var mode = "idel";
function Awake()
{
if(!target)
{
target = GameObject.FindWithTag("Player").transform;
LeftFlame.renderer.enabled = false;
RightFlame.renderer.enabled = false;
}
}
function Update ()
{
if(target CanAttackTarget())
{
//transform.LookAt(target);
var targetRotation = Quaternion.LookRotation(target.position - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 1.2);
var forward = transform.forward;
var targetDir = target.position - transform.position;
var angle = Vector3.Angle(targetDir, forward);
if(angle <10.0)
{
[COLOR="red"]DoDamage();[/COLOR]
}
else
{
}
}
}
[COLOR="red"]var damageTimer = 0.0;
function DoDamage()
{
if(damageTimer==0.0)
{
damageTimer = Time.time;
}
if((damageTimer+0.05) > Time.time)
{
return;
}
else
{
Player.HEALTH -= 1;
print(Player.HEALTH);
damageTimer = Time.time;
}
}
function CanAttackTarget()
{
//Check if the target is close enough
if(Vector3.Distance(transform.position, target.position) > range)
{ Disengage();
return false;
}
var hit : RaycastHit;
//Check if there's collision in between turret target
if(Physics.Linecast(transform.position, target.position, hit))
{
if(hit.collider.gameObject.tag !="Player")
{
Disengage();
return false;
}
else
{
Attack();
return true;
}
}
return true;
}
function Attack()
{
if(mode != "attack")
{
InvokeRepeating("FalconAnimate", 2, 0.05);
mode = "attack";
}
}
function Disengage()
{
if(mode !="idel")
{
CancelInvoke();
mode = "idel";
LeftFlame.renderer.enabled = false;
RightFlame.renderer.enabled = false;
}
}
[/COLOR]
InvokeRepeating("FalconAnimate", 0, 0.05);
function FalconAnimate()
{
if(LeftFlame RightFlame)
{
if(LeftFlame.renderer.enabled)
{
LeftFlame.renderer.enabled = false;
RightFlame.renderer.enabled = true;
}
else
{
LeftFlame.renderer.enabled = true;
RightFlame.renderer.enabled = false;
}
}
else
{
print("Effect on Turret not set!");
}
}
and this is my player script:
var h00 : Texture2D;
var h10 : Texture2D;
var h20 : Texture2D;
var h30 : Texture2D;
var h40 : Texture2D;
var h50 : Texture2D;
var h60 : Texture2D;
var h70 : Texture2D;
var h80 : Texture2D;
static var HEALTH = 80;
function Update()
{
var g_Health = gameObject.Find("g_Health");
if(HEALTH > 70)
{
g_Health.guiTexture.texture = h80;
return;
}
else if (HEALTH > 60)
{
g_Health.guiTexture.texture = h70;
return;
}
else if (HEALTH > 50)
{
g_Health.guiTexture.texture = h60;
return;
}
else if (HEALTH > 40)
{
g_Health.guiTexture.texture = h50;
return;
}
else if (HEALTH > 30)
{
g_Health.guiTexture.texture = h40;
return;
}
else if (HEALTH > 20)
{
g_Health.guiTexture.texture = h30;
return;
}
else if (HEALTH > 10)
{
g_Health.guiTexture.texture = h20;
return;
}
else if (HEALTH > 5)
{
g_Health.guiTexture.texture = h10;
return;
}
else if (HEALTH <= 0)
{
g_Health.guiTexture.texture = h00;
Application.LoadLevel(2);
return;
}
}
/*InvokeRepeating("subtract", 2, 0.5);
function subtract()
{
HEALTH -= 1;
print("health is now: "+HEALTH);
}*/
Thanks ![]()