Hi,
I need help to debug the following code:
#pragma strict
function Start () {
}
function Update () {
}
var plChar : Transform;
var threshold: int;
var power;
if((transform.position - plChar.transform.position).magnitude < threshold) {
rigidBody.AddForce((transform.position - plChar.transform.position).normalized * power);
}
Can someone help me?
Hello and god day, I check your code and have some mistakes, but anyway, you can debug any thing you want using the print() in unityscript (*.js), something like this:
This is how suppose to be:
#pragma strict
var plChar : Transform;
var threshold: float;
var power : float;
var tempDistance : float;
function Start () {
}
function Update () {
tempDistance = (transform.position - plChar.transform.position).magnitude;
if(tempDistance < threshold)
{
rigidBody.AddForce((transform.position - plChar.transform.position).normalized * power); //This have an error, if what you want to do it's some kind of "follow the gay", check the documentation.
}
print("The current distance is: " + tempDistance); //Here you can debug some values.
}
You need to check some things to make this work properly, cheers.