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 zoorroo4 · Jul 05, 2012 at 11:21 PM · c#getcomponent

Why are these scripts getting different icons and could it have anything to do with my problem?

Trying to get a script talk to another script..

Hi i have a problem with my project that i hope someone here could help me with. I got a script that handles an animation on a 2d-plane. The script looks like this:

 using UnityEngine;
 using System.Collections;
 
 public class Animation : MonoBehaviour
 {
     public int columnSize;
     public int rowSize;
     Vector2 size;
     Vector2 offset;
     int index;
   
     public void [B]Animate[/B](float rowFrameStart, int colFrameStart, int totalFrames, float framesPerSecond, bool isNegative)
     {
         size = new Vector2(1.000f / columnSize, 1.000f / rowSize);
 
         index = (int)(Time.time * framesPerSecond);
         //index %= (columnSize * rowSize);
         index %= totalFrames;
         
         int u = index % columnSize;
         int v = index / columnSize;
 
         offset = new Vector2((u + colFrameStart) * size.x, (1 - size.y) - (v + rowFrameStart) * size.y);
 
         if (isNegative)
         {
             offset = -offset;
         }
 
 
         SetScaleAndOffset(offset, size, true);      
     }
     
     
     private void SetScaleAndOffset(Vector2 offset, Vector2 size, bool haveNormalMap)
     {
         renderer.material.mainTextureOffset = offset;
         renderer.material.mainTextureScale = size;
 
         if (haveNormalMap)
         {
             renderer.material.SetTextureOffset("_BumpMap", offset);
             renderer.material.SetTextureScale("_BumpMap", size);
         }
     }   
 }






This script is attached to any objects that needs to have an animated material, the animation is then controlled by another script calling the method Animate. The code that does this is these lines, (or they should do it):

     private Animation animation;
 
  void Start () 
     {
         animation = gameObject.GetComponent("Animation") as Animation;
  }
 
  void Update () 
     {
         animation.Animate(0, 0, 16, 20, false);
     }


So both these scripts are attached to the same gameobjects. But when i try to test it out i get:

NullReferenceException: Object reference not set to an instance of an object

In the second script when i try to find a reference to the first script to run the method Animate something is wrong. animation = gameObject.GetComponent("Animation") as Animation; is´nt doing what it should. animation is equal to null, why? In the unity editor the two scripts got different icons, could it have something to do with that?

I made a picture to show you what i mean here

I hope you guys got an answer to my question.

EDIT * I managed to fix it by adding the animation script through the other script, so that i get a reference to it right away. But i still don´t get why the scripts got different icons..

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 delstrega · Jul 06, 2012 at 11:51 AM

If a script gets a different icon it is a good sign that there's a class with the same name used by Unity. http://docs.unity3d.com/Documentation/ScriptReference/Animation.html

Those icons are assigned by name and you can simulate that by creating a folder "Assets/Gizmos/" and putting a .png file " Icon.png" there (for example MySimpleAnimation Icon.png). Now every script with that class name will get this icon.

Animation is a unity internal class so you won't find a "Animation Icon.png" anywhere, but behind the scenes that's what happens there to: Your class is named "Animation" so it gets the icon.

EDIT: I guess Unity just gets confused since there's two possible "Animation" classes here. Try naming your classes more uniquely.

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

Answer by zoorroo4 · Jul 06, 2012 at 01:49 PM

Oh right unity also has a class named Animation, how silly of me not to notice. Thanks for the help :)

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

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

6 People are following this question.

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

Related Questions

Disable Scripts only works for one of the many 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Multi similar script Components same game object 1 Answer

I'm having more problems accessing a variable from another script in c# 2 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