Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Cookied8 · May 21, 2012 at 02:25 PM · animation

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Berenger · May 21, 2012 at 02:41 PM 2
Share

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.

avatar image whydoidoit · May 21, 2012 at 04:12 PM 0
Share

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 ';'

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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 ....

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · May 21, 2012 at 06:25 PM 0
Share

So i guess in the end it wasn't that urgent ...

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · May 22, 2012 at 10:15 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges