- Home /
Question by
sothern101 · Mar 14, 2014 at 09:14 AM ·
setactiveactive
Changing if a GameObject is active, not working for some parts of the script.
Okay so i'm making a mortal combat sort of game and when I try and set some Gameobjects active off and or on it works. But if I use mainSprite.active = false; (LINE 38 under the input of space), again for the second time it does not turn off the GameObject. Am I doing something wrong? And sorry if i didn't explain more clearly. Also i've tried SetActive and the others.
var walkSpeed : float = 3f;
var jumpHeight : float = 2f;
private var isGrounded : boolean = true;
var facingRight : boolean = true;
var jumpSprite : GameObject;
var mainSprite : GameObject;
var punchSprite : GameObject;
//Player Stats
public static var bcurHp : int = 100;
public static var bmaxHp : int = 100;
public static var bplayerGold : int = 0;
function Start ()
{
jumpSprite.active = false;
mainSprite.active = true;
punchSprite.active = false;
}
function Update ()
{
//Movement
if(Input.GetKey(KeyCode.A)){
transform.position += Vector3.left * walkSpeed * Time.deltaTime;
transform.rotation.y = 180;
}
if(Input.GetKey(KeyCode.D)){
transform.position += Vector3.right * walkSpeed * Time.deltaTime;
transform.rotation.y = 0;
}
if(Input.GetKeyDown(KeyCode.Space)){
punchSprite.active = true;
mainSprite.active = false;
}
if(isGrounded){
if(Input.GetKeyDown(KeyCode.W)){
rigidbody2D.AddForce(Vector3.up * jumpHeight);
}
}
if(!isGrounded){
if(Input.GetKeyDown(KeyCode.S)){
rigidbody2D.gravityScale = 10;
}
}
if(transform.position.y > 1){
isGrounded = false;
jumpSprite.active = true;
mainSprite.active = false;
}
else{
isGrounded = true;
jumpSprite.active = false;
mainSprite.active = true;
rigidbody2D.gravityScale = 2.1;
}
}
Comment