Hello everyone! First post here, but I already spent much time here looking for answers, and this community is awesome. I hope someday I’ll be skilled enough to help others.
Here is what I’m trying to do:
When I pick an item, it allows me to modify some rigidbodie’s drag parameter, so it slows them if I press a key. It all works fine, except I got this error:
NullReferenceException: Object reference not set to an instance of an object
PlayerDefense.FixedUpdate () (at Assets/2DJumpNRunFramework/Scripts/PlayerDefense.js:57)
But, it works fine when I’m playing in Unity. The problem is when I play with my GS2 on Unity Remote, sometimes it works, sometimes nothing happens when I press the key. And when I compile for Android and test it directly on my GS2, nothin ever happens.
Here is the code for when I press the button:
function SetSlowTime(slowget:float){
slowtime=slowtime+slowget;
}
function FixedUpdate () {
if(FdefenseDown() && slowtime>0){
print("baboum!");
slowtime=slowtime-1;
var Slowable = GameObject.FindGameObjectsWithTag("slowable" || "bullet");
if(Slowable!=null){
for(var g : GameObject in Slowable) {
g.GetComponent(SlowScript).slow();
}
}
}
}
And here is the code placed on every rigidbody:
function slow () {
if(rigidbody.drag == 0){
rigidbody.drag = 20;
rigidbody.angularDrag = 10;
yield WaitForSeconds (5);
rigidbody.drag = 0;
rigidbody.angularDrag = 0;}
else{
rigidbody.drag = 0;
rigidbody.angularDrag = 0;}
}
Does anyone knows about an issue with modifying rigidbodies properties on mobile devices?..
Thanks in advance.
Julien