- Home /
Question by
alcohollica · Jul 16, 2014 at 06:47 PM ·
javascript
Shutting a function when another function calling.
Hey everyone, I want to shut a function when I call another function, better for you to understand my code here,
var speed = 5.0f;
function Update () {
Normal();
}
function OnCollisionEnter(col : Collision){
if(col.gameObject.name == "LeftWall"){
transform.position.x += 30 * Time.deltaTime;
}
}
function Normal(){
transform.position.x -= speed * Time.deltaTime;
}
So How I do it :)
Comment
Best Answer
Answer by Kiwasi · Jul 16, 2014 at 06:51 PM
Use bool checking, like so:
var isCollided = false;
var speed = 5.0f;
function Update () {
Normal();
}
function OnCollisionEnter(col : Collision){
if(col.gameObject.name == "LeftWall"){
transform.position.x += 30 * Time.deltaTime;
isCollied = true;
}
}
function Normal(){
if (!isCollided){
transform.position.x -= speed * Time.deltaTime;
}
}
Oops, my mistake I changed wall name but i forget it :) But there is another question I get.Object collide with wall and it stops i want to make it running.How I do it?
Oh I fixed it again.There is no problem I get now :) Thanks for your answering. If someone else has, I solved this problem like that,
var isCollided = false;
var speed = 5.0f;
function Update () {
Normal();
if(isCollided){
transform.position.x += 5 * Time.deltaTime;
}
}
function OnCollisionEnter(col : Collision){
if(col.gameObject.name == "LeftWall"){
isCollided = true;
}
}
function Normal(){
if (!isCollided){
transform.position.x -= speed * Time.deltaTime;
}
}