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 Iceblitzyt · May 14, 2013 at 03:58 PM · c#arrays

how can i use an array to do multiple animations? c#

Hey there,

I want to make a system where my platform my player stands on changes with the animation I've set it up with. I created an array but i get an error, i must confess im still learning arrays as they don't agree with me. Anyways can anyone suggest what i can do? here is the current code:

 using UnityEngine;
 using System.Collections;
 
 public class CameraSwitch : MonoBehaviour {
     public GameObject Player;
     private GameObject[] Platform;
     public GameObject Playerobj;
     public AudioClip CameraSWtich;
     
     void Start(){
     Platform = GameObject.FindGameObjectsWithTag("Platform");    
     }
     
     void OnGUI () {
     if(PlayerPrefs.GetInt("ActionBar",0) == 1){
         if(GUI.Button(new Rect(Screen.width /2 -150,Screen.height/2 + 200,50,50),"3D")){
         audio.clip = CameraSWtich;
         audio.Play();
         animation.Play("3dCamera");
         Playerobj.animation.Play("playerout");
         Platform.animation.Play("brick3d");
         TP_Controller tpc = Player.GetComponent<TP_Controller>();
         tpc.thirdDOn = true;
         }
     }
 }
 }
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 SubatomicHero · May 15, 2013 at 07:14 AM 0
Share

What part isn't working? Its hard to tell just by looking at your script. What is the error you receive?

avatar image Iceblitzyt · May 15, 2013 at 11:00 AM 0
Share

sorry i forgot to add the error, this is the error : Type UnityEngine.GameObject[]' does not contain a definition for animation' and no extension method animation' of type UnityEngine.GameObject[]' could be found (are you missing a using directive or an assembly reference?)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SubatomicHero · May 15, 2013 at 11:21 AM

I think this could possibly solve your problem:

 // change this at the top
 private GameObject[] Platform;
 // to this:
 private Animation[] Platform;
 
 // In start change the code to this:
 void Start() {
     Platform = GameObject.FindGameObjectsWithTag("Platform") as Animation;
 }

Then update the code in your OnGUI function. WARNING this is untested code

Comment
Add comment · Show 5 · 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 Iceblitzyt · May 15, 2013 at 11:37 AM 0
Share

sorry it still doesn't work, i get this error : Type UnityEngine.Animation[]' does not contain a definition for animation' and no extension method animation' of type UnityEngine.Animation[]' could be found (are you missing a using directive or an assembly reference?)

It's odd tbf, I can't actually think of a way of doing it since it's multiple objects prefor$$anonymous$$g the same animation at once. :/

avatar image SubatomicHero · May 15, 2013 at 11:42 AM 0
Share

did you try changing:

 Platform.animation.Play("Whatever");
 
 // to this
 
 Debug.Log(Platform.toString());

So you can see what your array contains?

avatar image Iceblitzyt · May 15, 2013 at 11:50 AM 0
Share

Yes, I get these two errors : Cannot convert type UnityEngine.GameObject[]' to UnityEngine.Animation' via a built-in conversion

And : Type UnityEngine.Animation[]' does not contain a definition for toString' and no extension method toString' of type UnityEngine.Animation[]' could be found (are you missing a using directive or an assembly reference?)

avatar image SubatomicHero · May 15, 2013 at 11:58 AM 0
Share

ah then in start it should be

 Platform = FindObjectsofType(typeof(Animation)) as Animation[];

Also don't forget you need to access an element of your array, which I forgot to mention in my answer.

 // access the first element(animation) in your array
 Platform[0].animation.Play();
 
 // or you could use a for loop
 
 for (int i = 0; i < Platform.Length; i++)
 {
     Platform[i].animation.Play();
 }

But from now I think you need to play with your code, I've given enough ideas to help :D

avatar image Iceblitzyt · May 15, 2013 at 12:02 PM 1
Share

just tried that, have the exact same errors as last time. this doesn't want to work for us haha

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

14 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Using a Parameterized arraylist (C#)??? 1 Answer

Best way to keep track of objects on a 3D Grid? 2 Answers

How to debug values in jagged arrays? 0 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