Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need to code Enemy Attacking Portion of a Pokemon/Turned Based Combat System

Discussion in 'Scripting' started by MJG1123, May 28, 2015.

  1. MJG1123

    MJG1123

    Joined:
    Apr 12, 2015
    Posts:
    24
    Once the player has clicked a button to attack and the damage and such to the enemy has been calculated, I then need to run the function to calculate the damage the player takes AND DISPLAY THE TEXT/INFO the player needs to know on screen long enough/and possibly give the option to skip the text.
    (this is also posted in Unity Answers)
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      29.5 KB
      Views:
      629
  2. Deleted User

    Deleted User

    Guest

    So what's the problem?
     
  3. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Well first declare the health at the top, and then do a function that allows you to randomly generate Attack Damage using Random Range.

    As for displaying the text make a canvas>Text then something like...


    Code (CSharp):
    1. using UnityEditor.UI;
    2.  
    3. public Text playershealth;
    4. public int playersHP = 100;
    5.  
    6. void Update () {
    7. playershealth.text = playersHP.ToString();
    8. // this should display the health inside the text as long as the text is on canvas and you've dragged the text object to the Inspector once script is attached.
    9. }
     
  4. MJG1123

    MJG1123

    Joined:
    Apr 12, 2015
    Posts:
    24
    I have all that I literally just need to have text display when the enemy is attacking so the player knows what is going on look at this video
     
  5. MJG1123

    MJG1123

    Joined:
    Apr 12, 2015
    Posts:
    24
    I need to display text when the enemy is attacking so the player knows what is going on video
     
  6. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    do a boolean the that checks if attacking is on and then make your gui visable when attack and if false gui is inactive
     
  7. MJG1123

    MJG1123

    Joined:
    Apr 12, 2015
    Posts:
    24
    ok I found a much easier way in using the Invoke (); class, but can't seem to get it to work with calling a function from another script video
     
  8. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Just make a GUI image with text displaying which attack is happening , then make it inactive when it's players turn. Then when back onto AI turn, for ever attack have it display 'Enemy Attack1" and so on....