Search Unity

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:
      652
  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....