- Home /
So many script problems. Please help, urgent!
Hi there. I am currently trying to create an animation trigger, and the script I see everyone use is...
using UnityEngine;
public class ActivateTrigger : MonoBehaviour {
public enum Mode {
Trigger = 0, // Just broadcast the action on to the target
Replace = 1, // replace target with source
Activate = 2, // Activate the target GameObject
Enable = 3, // Enable a component
Animate = 4, // Start animation on target
Deactivate= 5 // Decativate target GameObject
}
/// The action to accomplish
public Mode action = Mode.Activate;
/// The game object to affect. If none, the trigger work on this game object
public Object target;
public GameObject source;
public int triggerCount = 1;///
public bool repeatTrigger = false;
void DoActivateTrigger () {
triggerCount--;
if (triggerCount == 0 || repeatTrigger) {
Object currentTarget = target != null ? target : gameObject;
Behaviour targetBehaviour = currentTarget as Behaviour;
GameObject targetGameObject = currentTarget as GameObject;
if (targetBehaviour != null)
targetGameObject = targetBehaviour.gameObject;
switch (action) {
case Mode.Trigger:
targetGameObject.BroadcastMessage ("DoActivateTrigger");
break;
case Mode.Replace:
if (source != null) {
Object.Instantiate (source, targetGameObject.transform.position, targetGameObject.transform.rotation);
DestroyObject (targetGameObject);
}
break;
case Mode.Activate:
targetGameObject.active = true;
break;
case Mode.Enable:
if (targetBehaviour != null)
targetBehaviour.enabled = true;
break;
case Mode.Animate:
targetGameObject.animation.Play ();
break;
case Mode.Deactivate:
targetGameObject.active = false;
break;
}
}
}
void OnTriggerEnter (Collider other) {
DoActivateTrigger ();
}
}
My problem is that I get a whole load of errors.
Is everyone able to help me please?
Thanks.
Your screenshot is way to small. Try to read what it says, double click to find the line with a problem and fix it. If you're lost, copy the error messages and past them here. If they are all the same, for the love of god, paste only one.
I guess most of the errors stem from that first one - from what I can make out it looks like it is complaining about a missing ';'
Answer by Bunny83 · May 21, 2012 at 04:20 PM
The code looks find except one thing that isn't clear. What is DestroyObject()
?
I guess you want `Destroy()`
You also might want to store the new object returned by Instantiate in the targetGameObject variable after you destroyed the old one, but i'm not sure if that's what you want. If so i would do it like this assuming that target and source are not the same object:
if (source != null) {
var oldTransform = targetGameObject.transform;
targetGameObject = Object.Instantiate (source, oldTransform.position, oldTransform.rotation) as GameObject;
Destroy(oldTransform.gameObject);
}
edit
Just zoomed into your "screenshot". I can't really read much of it, but i clearly can read that your filename is .JS while your script is C#. All those errors have an error id starting with BCExxxx which comes from the Boo / Unityscript crosscompiler. C# error ids start with CSxxxx.
So you might want to rename your file into .cs ....
Answer by arkman1231 · May 21, 2012 at 04:08 PM
You have a simple syntax problem it looks like, a missing token or too many tokens. Go to the first error you see in the build window. That's probably the one that's causing the others.
No, the main problem is he uses C# code in a .JS file. I wrote that in my answer ;) It's hard to see in this screenshot, but the filename is clearly .JS
Your answer
![](https://koobas.hobune.stream/wayback/20220613071742im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation problems 1 Answer
Animation / Distance 0 Answers
how to get a animation from other script on colision 1 Answer
How to call animation from another Script in C#? 1 Answer
How to click a 3d object in unity3d? 3 Answers