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 · Jan 04, 2013 at 04:34 PM · c#quest

How do i make my script count once an animation on another script has finished?

Hey guys,

so, im continuing making a little quest tracking system. I want it so when a enemy wolf dies or when i click B the counter goes up. I've set it up in code, however it counts +1 for when the animation is present so it counts to 10 automatically.

Here's the code for the quest tracker:

 using UnityEngine;
 using System.Collections;
 
 public class Quest1tracker : MonoBehaviour {
     public AudioClip Questcompletesound;
     public Transform NPC;
     public Transform Wolf;
 
     
 int counter = 0;
     int Maxcount = 10;
     
     
     void OnGUI(){
 
        GUI.Box( new Rect((Screen.width /2) +800,400,150,25), "Wolfs Killed " + counter + "/" + Maxcount);
 
        }
 
     void Update(){
         WolfHealth Eh = (WolfHealth)Wolf.GetComponent("WolfHealth");
         
        if (Input.GetKeyDown(KeyCode.B) || Eh.Deathanimation) {
             counter++;
        }
         
         if(counter == Maxcount) {
         audio.clip = Questcompletesound;
             audio.Play();
             
             NPC.GetComponent<Quest1Middle>().enabled = false;
             NPC.GetComponent<Quest1End>().enabled = true;
             GetComponent<Quest1Handintracker>().enabled = true;
             GetComponent<Quest1tracker>().enabled = false;
             
             
         }
         
         
        }
 }

And this is the wolf health script(which contains death and death animation):

 using UnityEngine;
 using System.Collections;
 
 public class WolfHealth : MonoBehaviour {
     public int MaxHealth = 320;
     public int CurHealth = 320;
     public int Death = 0;
     public GUIStyle Playercurhealthtext;
     public float HealthBarLength;
     public Transform Target;
     public GUIStyle Demonskin;
     public AnimationClip Deathanimation;
     
     
     void Start(){
 
         
         
     HealthBarLength = 200;    
         
     }
     
     void OnGUI () {
     
         float dist = Vector3.Distance(Target.position, transform.position);
         
         if( dist <15){
         
             GetComponent<EnemyAI>().enabled = true;
              
          GUI.Box(new Rect((Screen.width /2)+310,(Screen.height /2) +300,90,80),"", Demonskin);
         
             GUI.Box(new Rect((Screen.width /2) +110,(Screen.height /2) +300,200/(MaxHealth/CurHealth),20), CurHealth + "/" + MaxHealth, Playercurhealthtext);
         }
         if(dist > 20) {
             GetComponent<EnemyAI>().enabled = false;
             
         }
     }
     
         public void AdjustCurrentHealth(int Adj){
     
         CurHealth += Adj;
         
         if (CurHealth <0)
             CurHealth = 0;
         if(CurHealth > MaxHealth)
             CurHealth = MaxHealth;
         if(MaxHealth < 1)
             MaxHealth = 1;
         if(CurHealth == MaxHealth){
             animation.AddClip(Deathanimation, "Death");
             animation.Play();
             GetComponent<Deactivateparent>().enabled = true;
             GetComponent<EnemyAI>().enabled = false;
             GetComponent<WolfHealth>().enabled = false;
         }    
         
         HealthBarLength = (200) * (CurHealth/(float)MaxHealth);
         
         
         
     
     }
     
     
     
     public void update() {
     
          AdjustCurrentHealth(0);
     }
 }

So how might i be able to get the counter to go up at the end of death animation. Also, can it be done so it counts 1 per death animation as I'd like to have multiple targets.

Many thanks in advance.

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
1
Best Answer

Answer by Jeffom · Jan 04, 2013 at 05:32 PM

You can do something like this

     if(CurHealth == MaxHealth){
              KillWolf();
            } 

          *
          *
          *
 
 private void KillWolf()
 {
     animation.AddClip(Deathanimation, "Death");
     animation.Play();
     GetComponent<Deactivateparent>().enabled = true;
     GetComponent<EnemyAI>().enabled = false;
     GetComponent<WolfHealth>().enabled = false;
     
     Invoke("UpdateQuest",animation.clip.lenght );
 }
 
 private void UpdateQuest()
 {
 //call the update counter here

}

The UpdateQuest will called after the death animation. You should create some static manager that contains the questtrackers and then update the quest tracker from there

Hope this was helpful

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 · Jan 04, 2013 at 11:22 PM 0
Share

Doesn't work. mono says Invoke(UpdateQuest,animation.length) The length doesn't exist I (corrected the grammar mistake on the post for lenght). Also i get this error CS1502: The best overloaded method match for `UnityEngine.$$anonymous$$onoBehaviour.Invoke(string, float)' has some invalid arguments

avatar image Jeffom · Jan 07, 2013 at 01:41 PM 0
Share

try animation.clip.length

avatar image Iceblitzyt · Jan 07, 2013 at 02:01 PM 0
Share

I did that it still have this error error CS1502: The best overloaded method match for `UnityEngine.$$anonymous$$onoBehaviour.Invoke(string, float)' has some invalid arguments Also ins$$anonymous$$d of the counter being called in the health bar script. How do i make it so the value goes up on the separate quest tracker script?

avatar image Jeffom · Jan 09, 2013 at 02:20 PM 0
Share

use this Invoke("UpdateQuest",animation.clip.lenght ); my bad, forgot to add the string format

you should have a main tracker with your quest being tracked, if you don't know what i'm talking about searching for singletons and static variables, that should solve youre problem

avatar image Iceblitzyt · Jan 12, 2013 at 09:12 PM 0
Share

singletons worked thanks very much!! :)

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

9 People are following this question.

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

How do i make a quest in c# for my game? 1 Answer

Quests/Dialogue (C#) 0 Answers

Renderer on object disabled after level reload 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