Search Unity

Generator/gas canister script?

Discussion in 'Scripting' started by Deleted User, Apr 18, 2017.

  1. Deleted User

    Deleted User

    Guest

    Hey, everyone. I am Darkwood Productions, developer of the indie horror game, The Chaser (a spin-off to the 2013 horror game Slender: The Arrival) - now available on GameJolt. I need help editing my game's "activate generators" script and adding in a Void that allows the player to use the gas canister GameObject to turn on (change the Point Light from red to green) the generator GameObject. I have the generator code figured out, but, need help with the code for the gas canisters. Here's the Void's code I have so far:

    Code (CSharp):
    1.  
    2.  
    3. void GasCanister()
    4. {
    5.   if (Input.GetMouseButtonDown(0))
    6.         {
    7.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    8.             RaycastHit hit;
    9.             if (Physics.Raycast(ray, out hit))
    10. {
    11.             if(hit.collider.CompareTag("Gas Canister")
    12. {
    13.             bool CanisterFound = true;
    14.             int canisterIndex = 0;
    15.             HasGasCanister = true;
    16. }
    17.        if(hit.collider.gameObject == GasCanisters[canisterIndex])
    18. {
    19.             Destroy(GasCanister)
    20. }
    21. if(!canisterFound)
    22. {
    23.       Debug.Log("No gas canister found in array")
    24. }
    25. else
    26. {
    27.       GasCanister[canisterIndex].SetActive(false)
    28. }
    29.  
    30.  

    maxresdefault.jpg
    GasCanister.jpg
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    .....is this a help request or a poorly-conceived ad campaign?
     
    lordofduct likes this.
  3. Deleted User

    Deleted User

    Guest

    It's a help request, I only mentioned my game thinking someone would remember me from somewhere. Guess not.
    lol. I need help adding a feature that allows the player in my game to use a GameObject (i.e. Gas canister) to switch a light from red to green. Can someone please help me? It would be greatly appreciated. Thanks!
     
  4. laxbrookes

    laxbrookes

    Joined:
    Jan 9, 2015
    Posts:
    235
    When are you calling the function GasCanister()? Because you're not listening for the MouseButton clicks otherwise.... Would you not be better off moving this to the Update() function?