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 Debunklelel · Mar 27, 2020 at 10:44 AM · scripting problemui3d

Function not excuting dispite being called

Sorry to pester you all again, but I have another scripting problem. For context, I'm working on a turn-based RPG battle system, I'm having fun programming it but something really weird is happening (here's my code for reference).

 ///<summary>The folowing code outlines the functions and routines that make up the battle system,
 ///to begin with the program fetches the stats of the enemy and the player (HP, MP, Strength
 ///and resislience) and makes them the value of their respective varibles. 
 ///The main loop can then begin, the progam will first check the HP values of both parties
 ///player first, to determine wether their has been a win or a loss.
 /// A "coin" is then tossed to decide turn order, if the coin "lands" on "heads" 
 /// the player can take their action first on that turn. </summary>
 
 //Libaries are called here.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class Battle_System : MonoBehaviour
 {
     //Defintion of public varibles
     public Text BattleLog; //The battle log, tells the player what's happening.
     public Text HPCount; //The HP count, shows the remaining HP of the player.
     public Button Slash; //The button for the slash action, dose a physical attack
     
     //Player Stats
     public float P_HP;
     public float P_MP;
     public float P_Strength;
     public float P_Resilience;
 
     //Enemy Stats
     public float E_HP;
     public float E_MP;
     public float E_Strength;
     public float E_Resilience;
 
     //Definiton of private varibles
     private int coin; //The coin that'll be tossed before each round
     private float damage; //How much damage a target takes from an attack, used in calculations
     //Used in making the pauses between battle log changes
     float _interval = 1.5f;
     float _lastTime;
     
     
 
 
     //Initiates the varibles
     void Start()
     {
         //Explains to the player that they've encountered an enemy.
         BattleLog.text = ("Enemy approaches...");
         
         //Gives the player's stats a value
         P_HP = 20;
         P_MP = 10;
         P_Strength = 5;
         P_Resilience = 2;
 
         //Gives the Enemy's stats a value
         E_HP = 12;
         E_MP = 10;
         E_Strength = 5;
         E_Resilience = 2;
 
         // Tells the player their current HP
         HPCount.text = ("HP: " + P_HP);
 
         //Used in making the pauses between battle log changes, credit to kubajs for their
         //help with this
         _lastTime = Time.time;
 
         //Sets the existance of the Action buttons (Slash, Cast, Examine, and Satchel)
         //to false to stop the player spamming it and messing up the game
     }
 
     //The Main Loop
     void Update()
     {
         // The program waits 5 seconds to allow the player to read the battle log
         if (Time.time > _lastTime + _interval)
         {
             _lastTime = Time.time;
 
             //The HP of both parties are checked to dermine whether the battle has been won or lost
             if (P_HP <= 0)
             {
                 //Player has no HP, player loses
                 BattleLog.text = "You Lose...";
             }
             else if (E_HP <= 0)
             {
                 BattleLog.text = "You Win!";
             }
 
             //Only goes through the following if both sides have HP remaining
             else
             {
                 //The coin is flipped to detrmine the turn order for this round.
                 coin = Random.Range(0, 2);
                 Debug.Log("Coin=" + coin);
                 if (coin == 0)
                 {
                     //Heads, player goes first
                     BattleLog.text = "Your turn";
                 }
                 else if (coin == 1)
                 {
                     //Tails, enemy goes first
                     BattleLog.text = "Enemy's turn";
                     EAttack();
                 }
             }
         }
     }
     
     //Defintion of functions
     //Function for when the enemy makes a physical attack
     void EAttack()
     {
         //Game pauses to allow the player to read battle log
         if (Time.time > _lastTime + _interval)
         {
             _lastTime = Time.time;
             BattleLog.text = "Enemy attacks!";
             if (Time.time > _lastTime + _interval)
             {
                 _lastTime = Time.time;
                 //Another pause is done before damage calculation
                 damage = (E_Strength * Random.Range(0.8f, 1.2f)) - (P_Resilience * Random.Range(0.8f, 1.2f));
                 Debug.Log("Damage taken before rounding= " + damage);
                 //Rounds the damage down to the nearest whole number
                 damage = Mathf.Floor(damage);
                 Debug.Log("Damage taken after rounding= " + damage);
                 //If the damage taken is less than 1, the amount of damage taken becomes 1.
                 if (damage < 1)
                 {
                     damage = 1;
                 }
                 //The amount of damage taken is recorded in the battle log.
                 BattleLog.text = "You suffered " + damage + " points of damage.";
                 //Damage is applied to player HP
                 P_HP = P_HP - damage;
                 //Updates the HP count.
                 HPCount.text = ("HP: " + P_HP);
             }
         }
      }
 }

If you've managed to follow my comments so far across this monstrosity you'd notice a function called "EAttack()", when called this is supposed to make the enemy attack the player. But for some bizarre reason when unity gets to the line of code denoting to execute that function it completely skips over it like it didn't exist. Did I do something wrong?

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

0 Replies

· Add your reply
  • Sort: 

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

305 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 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 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

I have a bug with my UI. 1 Answer

Outline Shader not working correctly on blender models 0 Answers

Sprite shrinks when selected? 1 Answer

Move GameObject between two points using Scrollbar 2 Answers

Double Score Problem ? 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