x


why is this script not working

var health = 10; var TakeDamage : boolean;

function OnTiggerEnter(other : Collider){ if(other.tag == "Player"){ TakeDamage = true; } }

more ▼

asked Jul 04 '12 at 05:19 AM

svenaline gravatar image

svenaline
0 1 1 2

MIght need some clue as to what isn't working... You have two colliders I presume - at least one set to isTrigger = true and one of them having a rigidbody...

Jul 04 '12 at 05:35 AM whydoidoit

I answered var health : int = 10; but due to low karma my answer did not show up

Jul 04 '12 at 05:37 AM Linus

What should the script do? Should it only set TakeDamage to true? Or should it also decrease the health?

Jul 04 '12 at 11:38 AM Luci85
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The function is OnTriggerEnter not OnTiggerEnter unless you are referring to the children's comic character!

more ▼

answered Jul 04 '12 at 05:42 AM

whydoidoit gravatar image

whydoidoit
33.1k 12 23 101

xD

+1

Jul 04 '12 at 11:20 AM Bunny83
(comments are locked)
10|3000 characters needed characters left
var health : int = 10; 
var TakeDamage : boolean;

function OnTriggerEnter(other : Collider){ 
  if(other.tag == "Player"){ 
   TakeDamage = true; 
  } 
}

Please use code formating (select the code text and click the 1010101 button) when posting, as well as a copy of the error message in the future.

more ▼

answered Jul 04 '12 at 05:41 AM

Linus gravatar image

Linus
302 1 3 4

You still have the Tigger thingy so it won't do. Also,

var health = 10; 

does work. The compiler will cast the variable to the appropriate type.

Jul 04 '12 at 05:48 AM fafase

Yup, updated just now. And yes it is valid. Without the #pragma strict. I usually get error on those. Credit goes to Mike

Jul 04 '12 at 05:51 AM Linus

No, you don't get an error with var health = 10;
The type is determined by type inference. This is not the same as dynamical typing. The type is still statically typed. This does also work in C#

var health = 10;         // int variable
var health = 10.0;       // float variable
var TakeDamage = false;  // boolean variable

In this cases the compiler can determine the type from the value you're assign to it, but that doesn only work when you assign a value at variable declaration. This will type the variable dynamicly:

var health; // no type, so it's a dynamic variable
health = 10;
health = "foo";

Avoid dynamically typed variables. They are slow and can cause strange errors at runtime. The compiler can't detect such errors since the type isn't known at compile time.

Jul 04 '12 at 11:19 AM Bunny83
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3340

asked: Jul 04 '12 at 05:19 AM

Seen: 173 times

Last Updated: Jul 04 '12 at 11:38 AM