x


How to trigger a script in another game object

Hallo good people I'm new to Unity and Java but I'm trying hard :P I want my platform (MovingPlatform1) with attached script named "PlatformMoverY" to be trigged - collision with the trigger should change var "isMoving" to true. Script "PlatformMoverY" works perfectly, I manualy switch "isMoving" to true or false and it's OK. Here is script for the trigger, I don't know what's wrong

var movingPlatform : GameObject;

function Start(){
          movingPlatform = GameObject.Find("MovingPlatform1");
}

function OnTriggerEnter (other : Collider) {
    var PlatformMoverY : ScriptName = gameObject.GetComponent(ScriptName);
    if(other.gameObject.CompareTag("Player")){
        PlatformMoverY.isMoving = true;
    }
}

I'm siting on it an hour and I got" BCE0018: The name 'ScriptName' does not denote a valid type ('not found'). Did you mean 'UnityEditor.ScriptableWizard'?" Help please :)))

more ▼

asked Jan 15 '11 at 09:56 PM

kecaj gravatar image

kecaj
30 8 8 9

Is "ScriptName" not supposed to be "The name of the script?" :)

Jan 15 '11 at 09:59 PM OrangeLightning
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

Why did you try ScriptName if you don't have a script called that? I'm assuming you copied and pasted from a general example. You should have read a basic tutorial on JavaScript before attempting this, to find out what it means when you put something after the colon after a variable declaration. Also, JavaScript is not Java.

var platformMoverY : PlatformMoverY;

function Start() {
    platformMoverY = GameObject.Find("MovingPlatform1").GetComponent.<PlatformMoverY>();
}

function OnTriggerEnter (other : Collider) {
    if (other.CompareTag("Player")) platformMoverY.isMoving = true;
}
more ▼

answered Jan 15 '11 at 10:13 PM

Jessy gravatar image

Jessy
15.6k 72 95 196

Thanks but I got "BCE0022: Cannot convert 'boolean' to 'String'." What < > (triangle brackets, less-than, more-than) means here? I haven't found them in Unity Scripting Reference. I still read tutorials :)

Jan 15 '11 at 11:38 PM kecaj

That error didn't come from my code. The Generic form of GetComponent isn't documented for JavaScript yet, but that's the syntax for it. I don't know if you're ready to understand generics yet, but long story short, that's a better way to use fetch a component. Put "#pragma strict" at the top of your scripts, and that will alert you if you're not using GetComponent well.

Jan 15 '11 at 11:51 PM Jessy

My fault: "true" instead of true :) thanks

Jan 16 '11 at 12:13 AM kecaj
(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:

x986
x406
x29

asked: Jan 15 '11 at 09:56 PM

Seen: 1985 times

Last Updated: Jan 15 '11 at 10:04 PM