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 IKilledKenny_2 · Aug 21, 2014 at 04:31 AM · animationplayer

Use a script more than once?

Hello Unity3D i have a question about using the same script for more than one character?Is it possible to use the same script for more than one player?the reason why i ask this question is the fact that i have more than one character that needs to do combos and so far i only got one character to do so but i want another one to do it as well.If anyone know i can fix this problem.Can you please tell me how can i?

Script if anyone was wondering #pragma strict

 var combos : combosequence[] = new combosequence[3]; //Combo class. Fill this out in Inspector.
 var comboMaxTime : float = 1.0; //How long a timer for combo lasts in seconds. Fill this out in Inspector.
 var comboSpanTime : float = .25; //The span of when a combo can start. Fill this out in Inspector.
 var comboMidPoint : float = .5; //The position within the maxtime of a combo the span is active. Fill this out in Inspector.
 private var currentCombo : int = -1;
 private var comboTimeout : float = .0;
 AudioListener.volume = 100;
  
 function Update () {
     if (Input.GetKeyDown("u")) Attack();
     if (comboTimeout > 0) DecreaseTime();
 }
  
 function Attack () {
     ComboTime(); //Do all the logic for timing before animation etc.
     animation.Play(combos[currentCombo].comboAnimation); //Play the currentCombo combos' animation
     audio.clip = combos[currentCombo].comboSound; //Set the audio clip to the currentCombo combos' audio
     audio.Play(); //Finally play the audio
     audio.volume = 50;
  
     //Add logic for hitting enemies etc here!
  
 }
  
 function ComboTime () {
     if (currentCombo<combos.Length-1 && 
             comboTimeout>0 && 
             comboTimeout>comboMidPoint-comboSpanTime &&
             comboTimeout<comboMidPoint+comboSpanTime ||
             currentCombo==-1) {
             currentCombo++;
     } else {
         currentCombo = -1;
     }
     comboTimeout = comboMaxTime;
 }
  
 function DecreaseTime () {
     comboTimeout-=1*Time.deltaTime;
 }
  
 class ComboSequence {
     var comboName : String; //A name for current attack (might be of use later for tutorial or something else)
     var comboAnimation : String; //The animation name for current attack
     var comboSound : AudioClip; //The audio for current attack
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiwasi · Aug 21, 2014 at 04:52 AM

Yes. Its common practice to reuse scripts. Otherwise no one would finish anything. Couple of points to note.

  • Put your input in a separate component from your engine. That way your player(s) and ai can both use the same engine code.

  • Don't hardcode anything, write every thing in terms of variables that can be adjusted

  • Keep each script to a single task

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animated Object phases through Player 2 Answers

3d animation controller 0 Answers

How can I add Animation to this player movement script? or do I have to create a totally new one? 0 Answers

My character doesn't animate when I try to move him 0 Answers

How do I put a delay in this? 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