Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 prototyped · May 04 at 05:48 AM · runtimedynamiccardsdynamic variables

Card Game Unique abilities run dynamically

Hi guys so this has been stumping me, so I have a card game where cards have unique abilities, now these cards are scriptable objects and some cards have unique abilities on them. Im running into an issue of how to run the ability when it needs to be triggered. I made it dynamically get the component onto the object alt text

now i need the code to work when the condition the do is triggered but i cant explicitly hard code the name of the function in the triggering code (this is the triggering code in class "cardbehaviour)

     void Attack ()
     {
         CardTypes cardType = card.GetComponent<CardDisplay>().eCardtype;
         string cardDmg = card.transform.GetComponent<CardDisplay>().damageText.text;
         
         switch(cardType){
         case  CardTypes.BASIC:
             BattleManager.Targeting(int.Parse(cardDmg));
             break;
         
         case CardTypes.TECHNIQUE:
             executeTechnique = true;
             break;
         
         case CardTypes.PERRY:
         
              break;
         
         case  CardTypes.COUNTER:
         
              break;
 
         }


this is the class and code i want to have happen, but the update method im trying to use is making it do continuous damagae.

   void Update()
     {
        
         if (this.gameObject.GetComponent<CardBehaviour>().executeTechnique == true)
         {
             TechniqueExecution();
         }
     }
 
         public void TechniqueExecution()
         {
             CardForms cardForms = BattleManager.activePlayer.FormCard.GetComponent<CardDisplay>().eCardForm;
 
             if (cardForms == this.gameObject.GetComponent<CardDisplay>().eCardForm)
             {
                 
                 CrecentCannon();
                 
             }
             else
             {
                 this.gameObject.GetComponent<CardBehaviour>().executeTechnique = false;
                 CresecntKickStandard();
                 
             }
         }
ability.png (7.7 kB)
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
2
Best Answer

Answer by MickyX · May 04 at 09:53 AM

I think you need to look at using a UnityEvent this allows you to add multiple functions in the inspector and call them, so you don't need the name https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html

I have a similar scenario where I want to be able to run different events when the player collides with Triggers, but I don't want to have to create separate scripts each time. So I use UnityEvents attached to the gameobject and I can assign as many or as few actions as I want in the inspector with no additional coding

  public UnityEvent FunctionsToCall;

That will give you the below, so just like a UI Button event alt text

You can then drag in any scripts onto that and assign the commands you want to run

To call all the events use

 FunctionsToCall.Invoke();

You should be able to create a card, add the functionstoacall script assign all the events you want to run and invoking the events from your other script when you called "ExecuteTechnique" This should allow for the same call on all cards but allow you to set different functions on each card. Therefore not needing the name of the function you want to call.

Just a couple of other points,

  1. you should create a reference to the CardBehaviour, calling GetComponent every update is expensive, just add it to your Start routine

  2. I think it's calling multiple times because you only set executeTechnique back to false in the else section so it can call CrecentCannon everyframe


unityevent.jpg (25.8 kB)
Comment
Add comment · Show 3 · 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 prototyped · May 04 at 04:42 PM 0
Share

MMMMMMM NOW THAT SOUND LIKE SOMETHIN I CAN GET INTO letme try that

avatar image prototyped · May 05 at 10:15 PM 0
Share

yo my mans this was the ticket thanks a lot fam

avatar image MickyX prototyped · May 05 at 10:19 PM 0
Share

No probs, glad it helped. Good luck

avatar image
1

Answer by QuaternionProduceZ · May 04 at 09:59 AM

What I normally do to make sure something in the Update Method is running once, is add a boolean like "alreadyDamaged", setting it to false at the start, and then making it true just after the code required is run.

In your case,

      if (this.gameObject.GetComponent<CardBehaviour>().executeTechnique == true && alreadyDamaged == false)
      {
          TechniqueExecution();
           alreadyDamaged = true;
      }


I am just a beginner, so if this is not what you are looking for... do tell

Comment
Add comment · Show 1 · 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 prototyped · May 05 at 10:16 PM 0
Share

this is an answer and i had to mix this one with the one above to get it to work so the input was just as good thanks fam!!! :D

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

137 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dynamicaly Creating A Plane With A JPG Material ... 2 Answers

Dynamically load AudioClip during runtime 1 Answer

Export objects to a .3DS file at runtime 1 Answer

Accessing Dynamically Named Variables (javascript) 2 Answers

Saving gameobjects' properties for Dynamically growing prefabs 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