x


small example sendmessage from javascript to C# wrong???

I tried to search and read many ways to access variable from javascript to C# I tried this compile

However I get no result. Here is my process:

First, I create new Project

Second, I create folder Plugins

Third, I create 1 C# script called "Cshape"

using UnityEngine; using System.Collections;

public class Cshape : MonoBehaviour {

    void ApplyDamage(float damage)    {
    print ("a");   } }

and 1 Java script called "Java"

function Update(){ GameObject.SendMessage ("ApplyDamage", 5.0); }

How can I call the function ApplyDamage from Cshape script? Thanks for any help Regards.

more ▼

asked Jul 15 '11 at 11:23 AM

superstar123 gravatar image

superstar123
28 7 8 11

And did you add these scripts to a GameObject?

Jul 15 '11 at 11:40 AM Waz

Yes, of course, and I put 2 scripts into the folder "Plugins" but it not work :( Can someone help me?

Jul 15 '11 at 11:48 AM superstar123

Thanks, I did it man

Jul 15 '11 at 01:03 PM superstar123
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

OK I find the solution here, the JavaScript "Java" should be like this :

function Update() { gameObject.Find("NameOfObjectAttatchThisScript ").GetComponent("Cshape").SendMessage ("ApplyDamage", 5.0);

}

yup, this should work, just create the object with name "NameOfObjectAttatchThisScript" :p

more ▼

answered Jul 15 '11 at 01:02 PM

superstar123 gravatar image

superstar123
28 7 8 11

(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:

x4359
x3565
x232
x154

asked: Jul 15 '11 at 11:23 AM

Seen: 2828 times

Last Updated: Jul 15 '11 at 01:03 PM