Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Xatoku · Aug 14, 2011 at 05:10 PM · arraylistenemythrough

Array Help

Hey guys, I'm trying to clean up my scripts and convert this one in particular into an array. I've never used Arrays before and the Script Reference kind of confused me, so I'm asking if someone would be willing to convert this to an array and explain it to me. Basically, the script enables a HitSpark (small sprite sequence for when something's hit) and goes through each sprite, turning off once the sequence is done. I essentially want to be able to just drag this script onto any Enemy and be able to input the values and add the respective number of sprites, but currently I'm forced to make a new script for each sequence depending on their total number of sprites.

 var HS1 : Material; 
 var HS2 : Material; 
 var HS3 : Material; 
 var HS4 : Material; 
 var HS5 : Material; 
 
 var Speed = 0.1;
 var HitSpark1 : Transform;
 var HitSpark2 : Transform;
 
 var started:boolean = false;
 var showing:boolean = false;
 
 function Start(){
     HitSpark1.renderer.material = HS1; 
     HitSpark2.renderer.material = HS1; 
     yield WaitForSeconds(Speed);
     HitSpark1.renderer.material = HS2;
     HitSpark2.renderer.material = HS2;
     yield WaitForSeconds(Speed);
     HitSpark1.renderer.material = HS3;
     HitSpark2.renderer.material = HS3;
     yield WaitForSeconds(Speed);
     HitSpark1.renderer.material = HS4;
     HitSpark2.renderer.material = HS4;
     yield WaitForSeconds(Speed);
     HitSpark1.renderer.material = HS5;
     HitSpark2.renderer.material = HS5;
     yield WaitForSeconds(Speed);
     showing = false;
     started = false;
 }
 
 function Update () 
 {
     if(started){
         showing = true;
         started = false;
         if(!started){
             Start();
         }
     }
     if(showing){
         HitSpark1.renderer.enabled = true;
         HitSpark2.renderer.enabled = true;
     }else{
         HitSpark1.renderer.enabled = false;
         HitSpark2.renderer.enabled = false;
     }
 }
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

Answer by DaveA · Aug 14, 2011 at 06:41 PM

Something like

 var HS : Material[]; 
 
 var HitSpark : Transform[];
 
 
 for (var i = 0; i < HS.length; i++)
 {
   for (var j = 0; j < HitSpark.length; j++)
     HitSpark[j].renderer.material = HS[i];
   yield WaitForSeconds(Speed);
 }
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 $$anonymous$$ · Aug 14, 2011 at 06:47 PM

 var HS : Material[];
 vat HitSpark: Transform[];

drag the prefabs in the inspector.

 HitSpark[0].renderer.enabled = true;

you can create a int variable to represents this index.

 private var  indx : int = 0;
 
 indx = 5;
 
 HitSpark[indx].renderer.enabled = true;


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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Array out of range 1 Answer

Remove object from List after gameObject was destroyed in between Scene loads 1 Answer

How to cycle through targets? 2 Answers

How to arrange list 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