• 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 ckannon · Jul 09, 2010 at 03:25 AM · namespace

Running Functions from other scripts?

I'm using C# for my game and the Detonator package. For some reason the below code is telling me that the Detonator object namespace cannot be found. I have it attached to a gameobject with a Detonator script also attached. Can anyone shed some light?

public void OnTriggerEnter(Collider other) {
    GameObject go = other.gameObject;       
    Detonator dn = go.GetComponent<Detonator>();        
    dn.Explode();
}

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ckannon · Jul 10, 2010 at 09:16 PM

I solved the problem. The error was due to not having my Camera object tagged as Main Camera. Hopefully this will save some grief for others in the future.

Thanks for the help!

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 Cyclops · Jul 10, 2010 at 10:55 PM 0
Share

@ckannon, please checkmark your answer to close it (it may take a few days before you can, however).

avatar image
0

Answer by Cyclops · Jul 09, 2010 at 01:41 PM

I'm not sure what's causing the error, but just to make sure you didn't miss anything, here are the steps you should have followed to use the Detonator package.

  • Import the package using Assets->Import Package. Make sure everything is checked.

If the import worked, you should see several new directories, specifically Prefab Examples and System.

  • From the System directory in the Project tab, drag/drop a Component Script called Detonator. Not the Prefab called Detonator - Base, which would be a GameObject, not a Component.

One simple way to test it without relying on a Collider, is to create a new public GO variable on your Script object, and drag/drop the Object with the Detonator script to it:

public GameObject someBomb;

void OnMouseUp() { Detonator foo = someBomb.GetComponent<Detonator>(); if (foo == null) Debug.Log("wups no foo"); else { Debug.Log("foo booming"); foo.Explode(); } }

I always like to check found Components for null. Especially for Scripts - if there are errors in them, they don't compile, and references to them get nulled, leaving you wondering why a working Script suddenly broke...

Comment
Add comment · Show 2 · 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 Mike 3 · Jul 09, 2010 at 01:53 PM 0
Share

Doesn't account for the error though - That to me signifies the Detonator script is missing

avatar image Cyclops · Jul 09, 2010 at 01:57 PM 0
Share

@$$anonymous$$ike yeah, I was just thinking about that - tried to duplicate the error, haven't so far. But maybe if he follows my description (import package, drag/drop script) it will help him find whatever's missing.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

'The type or namespace name could not be found' 1 Answer

Using Namespaces? 1 Answer

Put a script as a variable in C#? 2 Answers

Helicopter Crash Collision 0 Answers

My health decreases to fast. 1 Answer


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