• 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 Yujelli · Jul 01, 2013 at 05:29 AM · functionsglobal

Is it possible to store a game's level-specific functions in one game object and have my animation events reference those functions?

I'm specifically using EX2D which lets me type in my method name for my animation event and I was wondering if I would have to put the specific functions on one script, and place that script on every object to be able to use it or if I could just have one gameObject that gets automatically called via an animation event.

My example would be that I want a sprite object to add to a global variable and spawn a particle with cooresponding number above the tapped game object.

I have code to do this on the gameObject's script and it works fine but the function is so specific to this one stage that it feels sloppy. I imagine I'm missing some huge revelation on how C# works.

I'm not asking for anyone to write the code for me but at least a point in the right direction would be fantastic. I'll show what I have for my locally-declared function to give you an idea of what I'm doing and I'm certain it'll be great for a laugh.

 public void Count (){
         GameObject.Find ("root").GetComponent <root>().intCount++;
         int intCount = GameObject.Find ("root").GetComponent<root>().intCount;
         playRefSound (GameObject.Find ("root").GetComponent <root>().intCount.ToString ());
         GameObject NumParticle = (GameObject) Instantiate(Resources.Load ("NumberParticle"), gameObject.transform.position + new Vector3(0,40,0),Quaternion.Euler (270,0,0));
         NumParticle.GetComponent<ParticleSystem>().renderer.material.mainTexture = Resources.Load ("Numbers/"+intCount.ToString()) as Texture2D;
         Destroy (NumParticle,10);
     }

So this is on a script called SpriteProperties which is on every tappable sprite. It feels like I should be able to stick this on an empty game object, yet still be able to pass an animation event to it as well as the location of the tapped object for instantiating the particle.

Am I just all kinds of backed up over here? Thanks for your time.

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

0 Replies

· Add your reply
  • Sort: 

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

15 People are following this question.

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

Related Questions

How do you store a function in a variable in c#? 2 Answers

Getting the (instantaneous) normal of a meshfilter object 2 Answers

project wide variables and constants 2 Answers

Global array list c# 1 Answer

Problem with world coordinates in scripts? 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