1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

[UNITY 5 FPS Tutorials] GTGD S3 - Advanced First Person Shooter

Discussion in 'Community Learning & Teaching' started by GTGD, Oct 9, 2015.

  1. vladalbescu

    vladalbescu

    Joined:
    Jun 8, 2017
    Posts:
    1


    My attempt at the S3 Chapter 1 challenge. For unknown reasons, it didn't record from the beginning of the game, when there were no evil cubes and all was chill.
     
    GTGD and KUFgoddess like this.
  2. KUFgoddess

    KUFgoddess

    Joined:
    Apr 2, 2015
    Posts:
    8
    Does anyone know how to add health to the player on trigger enter?? My player walks across a box to receive health. I am on chapter 9 and I have been trying to do this for weeks and no luck I feel like im very warm but it just is giving me so much trouble ive tried so many combinations. Like I keep looking at how the enemy script is set up and im trying to do it like but no success.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.UI;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine;
    6.  
    7. namespace SpaceHorror
    8. {
    9.     public class Player_Health : MonoBehaviour
    10.     {
    11.         private GameManager_Master gameManagerMaster;
    12.         private Player_Master playerMaster;
    13.         public int playerHealth;
    14.         public string Oddity;
    15.         public Text healthText;
    16.  
    17.  
    18.  
    19.         void OnTriggerEnter(Collider other)
    20.         {
    21.             if (other.CompareTag("Player"))
    22.             {
    23.                 IncreaseHealth();  //<--- this is making it not compile but im not sure if this even makes sense.
    24.  
    25.  
    26.  
    27.             }
    28.  
    29.             SetUI();
    30.         }
    31.                 //void OnTriggerEnter(Collider other)
    32.                 //{
    33.                 //    if (other.CompareTag("Player"))
    34.                 //    {
    35.                 //        playerMaster.CallEventPlayerHealthIncrease = GetComponent<Player_Master>();
    36.  
    37.                 //        Player_Master playerMaster = GetComponent<OtherScript>();
    38.                 //        otherScript.DoSomething();
    39.                 //        //playerMaster.EventPlayerHealthIncrease += IncreaseHealth;
    40.                 //        SetUI();
    41.  
    42.                 //        //playerMaster.GetComponent<Player_Master>().EventPlayerHealthIncrease(increase);
    43.                 //    }
    44.                 //    {
    45.                 //        if (playerHealth > 100)
    46.                 //        {
    47.  
    48.                 //        }
    49.  
    50.  
    51.                 //        //playerMaster.GetComponent<Player_Master>().EventPlayerHealthIncrease(increase);
    52.  
    53.  
    54.                 //    }
    55.                 //}
    56.  
    57.  
    58.                 void OnEnable()
    59.         {
    60.             SetInitialReferences();
    61.             SetUI();
    62.             playerMaster.EventPlayerHealthDeduction += DeductHealth;
    63.             playerMaster.EventPlayerHealthIncrease += IncreaseHealth;
    64.         }
    65.  
    66.         void OnDisable()
    67.         {
    68.             playerMaster.EventPlayerHealthDeduction -= DeductHealth;
    69.             playerMaster.EventPlayerHealthIncrease -= IncreaseHealth;
    70.         }
    71.  
    72.         //void Start()
    73.         //{
    74.         //    StartCoroutine(TestHealthIncrease());
    75.         //}
    76.  
    77.      
    78.         void SetInitialReferences()
    79.         {
    80.             gameManagerMaster = GameObject.Find("GameManager").GetComponent<GameManager_Master>();
    81.             playerMaster = GetComponent<Player_Master>();
    82.         }
    83.  
    84.         //IEnumerator TestHealthIncrease()
    85.         //{
    86.         //    yield return new WaitForSeconds(4);
    87.         //   IncreaseHealth(300);
    88.         //    playerMaster.CallEventPlayerHealthIncrease(1);
    89.         //}
    90.  
    91.         void DeductHealth(int healthChange)
    92.         {
    93.             playerHealth -= healthChange;
    94.             if(playerHealth<=0)
    95.             {
    96.                 playerHealth = 0;
    97.                 gameManagerMaster.CallEventGameOver();
    98.                 SceneManager.LoadScene(Oddity);
    99.  
    100.  
    101.             }
    102.  
    103.             SetUI();
    104.  
    105.         }
    106.  
    107.  
    108.  
    109.  
    110.         void IncreaseHealth(int healthChange)
    111.         {
    112.  
    113.             playerHealth += healthChange;
    114.  
    115.             if(playerHealth>=100)
    116.             {
    117.                 playerHealth = 100;
    118.             }
    119.  
    120.             SetUI();
    121.         }
    122.  
    123.  
    124.  
    125.      
    126.  
    127.  
    128.         void SetUI()
    129.         {
    130.             healthText.text = playerHealth.ToString();
    131.         }
    132.     }
    133. }
     
  3. KUFgoddess

    KUFgoddess

    Joined:
    Apr 2, 2015
    Posts:
    8
    Hey did anyone figure out how to ADD health to the player?
     
  4. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    307
    YouTube will help you with good tutorial.
     
  5. VCGhost

    VCGhost

    Joined:
    Sunday
    Posts:
    5
    Error.png
    thank you for you nice teaching style I found your tutorials really nice
    would you please tell me that why is this error appearing I wrote the same script as you wrote in video for menu UI script
     
  6. VCGhost

    VCGhost

    Joined:
    Sunday
    Posts:
    5
    and this is the script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. namespace S3
    5. {
    6.     public class GameManager_ToggleMenu : MonoBehaviour
    7.     {
    8.         private GameManager_Master gameManagerMaster;
    9.         public GameObject menu;
    10.  
    11.  
    12.         // Use this for initialization
    13.         void Start()
    14.         {
    15.             ToggleMenu();
    16.         }
    17.  
    18.         // Update is called once per frame
    19.         void Update()
    20.         {
    21.             CheckForToggleMenuRequest();
    22.         }
    23.         void OnEabled()
    24.         {
    25.             SetInitialRefrences();
    26.             gameManagerMaster.GameOverEvent += ToggleMenu;
    27.         }
    28.  
    29.         void OnDisabled()
    30.         {
    31.             gameManagerMaster.GameOverEvent -= ToggleMenu;
    32.         }
    33.  
    34.         void SetInitialRefrences()
    35.         {
    36.             gameManagerMaster = GetComponent<GameManager_Master>();
    37.         }
    38.  
    39.         void CheckForToggleMenuRequest()
    40.         {
    41.             if (Input.GetKeyUp(KeyCode.Escape) && !gameManagerMaster.isGameOver && !gameManagerMaster.isInventoryUIOn)
    42.             {
    43.                 ToggleMenu();
    44.             }
    45.         }
    46.  
    47.         void ToggleMenu()
    48.         {
    49.             if (menu != null)
    50.             {
    51.                 menu.SetActive(!menu.activeSelf);
    52.                 gameManagerMaster.isMenuOn = !gameManagerMaster.isMenuOn;
    53.                 gameManagerMaster.CallEventMenuToggle();
    54.             }
    55.             else
    56.             {
    57.                 Debug.LogWarning("You Need To Assign a UI Game Object To The Toggle Menu Script In Inspector.");
    58.             }
    59.         }
    60.     }
    61. }
     
  7. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    307
    Put this issue on this section.
    https://forum.unity3d.com/forums/scripting.12/
     
  8. GTGD

    GTGD

    Joined:
    Feb 7, 2012
    Posts:
    418
    Look at the name of your OnEnable and OnDisable methods. They are Unity methods and must match the Unity names exactly or else they are never called
     
  9. VCGhost

    VCGhost

    Joined:
    Sunday
    Posts:
    5
    really thanks for your help and the attention that you have for answering questions
     
  10. VCGhost

    VCGhost

    Joined:
    Sunday
    Posts:
    5
    Hi
    Thank you for your great tutorials
    Would you please tell me how can I solve this error
    It's complaining about Item Ammo script and it's the error
    Error.png
    I really need you help