Search Unity

Need Help With This (IMPORTANT) 2

Discussion in 'Editor & General Support' started by HopeNotFound, Apr 13, 2021.

  1. HopeNotFound

    HopeNotFound

    Joined:
    Apr 11, 2021
    Posts:
    4
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Runtime.Remoting.Messaging;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.SceneManagement;
    7. using UnityStandardAssets.Characters.FirstPerson;
    8.  
    9. public class PlayerBehaviour : MonoBehaviour
    10. {
    11.     [Header("Health Settings")]
    12.     public GameObject healthSlider;
    13.     public float health = 100;
    14.     public float healthMax = 100;
    15.     public float healValue = 5;
    16.     public float secondToHeal = 10;
    17.  
    18.     [Header("Flashlight Battery Settings")]
    19.     public GameObject Flashlight;
    20.     public GameObject batterySlider;
    21.     public float battery = 100;
    22.     public float batteryMax = 100;
    23.     public float removeBatteryValue = 0.05f;
    24.     public float secondToRemoveBaterry = 5f;
    25.  
    26.     [Header("Audio Settings")]
    27.     public AudioClip slenderNoise;
    28.     public AudioClip cameraNoise;
    29.  
    30.     [Header("Page System Settings")]
    31.     public List<GameObject> pages = new List<GameObject>();
    32.     public int collectedPages;
    33.  
    34.     [Header("UI Settings")]
    35.     public GameObject inGameMenuUI;
    36.     public GameObject pickUpUI;
    37.     public GameObject finishedGameUI;
    38.     public GameObject pagesCount;
    39.     public bool paused;
    40.  
    41.     void Start ()
    42.     {
    43.         // set initial health values
    44.         health = healthMax;
    45.         battery = batteryMax;
    46.  
    47.         healthSlider.GetComponent<Slider>().maxValue = healthMax;
    48.         healthSlider.GetComponent<Slider>().value = healthMax;
    49.  
    50.         // set initial battery values
    51.         batterySlider.GetComponent<Slider>().maxValue = batteryMax;
    52.         batterySlider.GetComponent<Slider>().value = batteryMax;
    53.  
    54.         // start consume flashlight battery
    55.         StartCoroutine(RemoveBaterryCharge(removeBatteryValue, secondToRemoveBaterry));
    56.     }
    57.    
    58.     void Update ()
    59.     {
    60.         // update player health slider
    61.         healthSlider.GetComponent<Slider>().value = health;
    62.  
    63.         // update baterry slider
    64.         batterySlider.GetComponent<Slider>().value = battery;
    65.  
    66.         // if health is low than 20%
    67.         if(health / healthMax * 100 <= 20 && health / healthMax * 100 != 0)
    68.         {
    69.             Debug.Log("You are dying.");
    70.             this.GetComponent<AudioSource>().PlayOneShot(slenderNoise);
    71.         }
    72.  
    73.         // if health is low than 0
    74.         if (health / healthMax * 100 <= 0)
    75.         {
    76.             Debug.Log("You are dead.");
    77.             health = 0.0f;
    78.         }
    79.  
    80.         // if battery is low 50%
    81.         if (battery / batteryMax * 100 <= 50)
    82.         {
    83.             Debug.Log("Flashlight is running out of battery.");
    84.             Flashlight.transform.Find("Spotlight").gameObject.GetComponent<Light>().intensity = 2.85f;
    85.         }
    86.  
    87.         // if battery is low 25%
    88.         if (battery / batteryMax * 100 <= 25)
    89.         {
    90.             Debug.Log("Flashlight is almost without battery.");
    91.             Flashlight.transform.Find("Spotlight").gameObject.GetComponent<Light>().intensity = 2.0f;
    92.         }
    93.  
    94.         // if battery is low 10%
    95.         if (battery / batteryMax * 100 <= 10)
    96.         {
    97.             Debug.Log("You will be out of light.");
    98.             Flashlight.transform.Find("Spotlight").gameObject.GetComponent<Light>().intensity = 1.35f;          
    99.         }
    100.  
    101.         // if battery out%
    102.         if (battery / batteryMax * 100 <= 0)
    103.         {
    104.             battery = 0.00f;
    105.             Debug.Log("The flashlight battery is out and you are out of the light.");
    106.             Flashlight.transform.Find("Spotlight").gameObject.GetComponent<Light>().intensity = 0.0f;
    107.         }
    108.  
    109.         // page system
    110.         pagesCount.GetComponent<Text>().text = "Collected Pages: " + collectedPages + "/8";
    111.  
    112.         //animations
    113.         if (Input.GetKey(KeyCode.LeftShift))
    114.             this.gameObject.GetComponent<Animation>().CrossFade("Run", 1);
    115.         else
    116.             this.gameObject.GetComponent<Animation>().CrossFade("Idle", 1);
    117.  
    118.         // collected all pages
    119.         if (collectedPages >= 8)
    120.         {
    121.             Debug.Log("You finished the game, congratulations...");
    122.             Cursor.visible = true;
    123.  
    124.             // disable first person controller and show finished game UI
    125.             this.gameObject.GetComponent<FirstPersonController>().enabled = false;
    126.             inGameMenuUI.SetActive(false);
    127.             finishedGameUI.SetActive(true);      
    128.  
    129.             // set play again button
    130.             Button playAgainBtn = finishedGameUI.gameObject.transform.Find("PlayAgainBtn").GetComponent<Button>();
    131.             playAgainBtn.onClick.AddListener(this.gameObject.GetComponent<MenuInGame>().PlayAgain);
    132.  
    133.             // set quit button
    134.             Button quitBtn = finishedGameUI.gameObject.transform.Find("QuitBtn").GetComponent<Button>();
    135.             quitBtn.onClick.AddListener(this.gameObject.GetComponent<MenuInGame>().QuitGame);
    136.         }
    137.     }
    138.  
    139.     public IEnumerator RemoveBaterryCharge(float value, float time)
    140.     {
    141.         while (true)
    142.         {
    143.             yield return new WaitForSeconds(time);
    144.  
    145.             Debug.Log("Removing baterry value: " + value);
    146.  
    147.             if (battery > 0)
    148.                 battery -= value;
    149.             else
    150.                 Debug.Log("The flashlight battery is out");
    151.         }
    152.     }
    153.  
    154.     public IEnumerator RemovePlayerHealth(float value, float time)
    155.     {
    156.         while (true)
    157.         {
    158.             yield return new WaitForSeconds(time);
    159.  
    160.             Debug.Log("Removing player health value: " + value);
    161.  
    162.             if (health > 0)
    163.                 health -= value;
    164.             else
    165.             {
    166.                 Debug.Log("You're dead");
    167.                 paused = true;
    168.                 inGameMenuUI.SetActive(true);
    169.                 inGameMenuUI.transform.Find("ContinueBtn").gameObject.GetComponent<Button>().interactable = false;
    170.                 inGameMenuUI.transform.Find("PlayAgainBtn").gameObject.GetComponent<Button>().interactable = true;
    171.             }
    172.         }
    173.     }
    174.  
    175.     // function to heal player
    176.     public IEnumerator StartHealPlayer(float value, float time)
    177.     {
    178.         while (true)
    179.         {
    180.             yield return new WaitForSeconds(time);
    181.  
    182.             Debug.Log("Healling player value: " + value);
    183.  
    184.             if (health > 0 && health < healthMax)
    185.                 health += value;
    186.             else
    187.                 health = healthMax;
    188.         }
    189.     }
    190.  
    191.     // page system - show UI
    192.     private void OnTriggerEnter(Collider collider)
    193.     {
    194.         // start noise when reach slender
    195.         if (collider.gameObject.transform.tag == "Slender")
    196.         {
    197.             if (health > 0 && paused == false)
    198.             {
    199.                 this.GetComponent<AudioSource>().PlayOneShot(cameraNoise);
    200.                 this.GetComponent<AudioSource>().loop = true;
    201.             }          
    202.         }
    203.  
    204.         if (collider.gameObject.transform.tag == "Page")
    205.         {
    206.             Debug.Log("You Found a Page: " + collider.gameObject.name + ", Press 'E' to pickup");
    207.             pickUpUI.SetActive(true);    
    208.         }
    209.     }
    210.  
    211.     // page system - pickup system
    212.     private void OnTriggerStay(Collider collider)
    213.     {
    214.         if (collider.gameObject.transform.tag == "Page")
    215.         {      
    216.             if (Input.GetKeyDown(KeyCode.E))
    217.             {
    218.                 Debug.Log("You get this page: " + collider.gameObject.name);
    219.  
    220.                 // disable UI
    221.                 pickUpUI.SetActive(false);
    222.  
    223.                 // add page to list
    224.                 pages.Add(collider.gameObject);
    225.                 collectedPages ++;
    226.  
    227.                 // disable game object
    228.                 collider.gameObject.SetActive(false);
    229.             }
    230.         }
    231.     }
    232.  
    233.     private void OnTriggerExit(Collider collider)
    234.     {
    235.         // remove noise sound
    236.         if (collider.gameObject.transform.tag == "Slender")
    237.         {
    238.             if (health > 0 && paused == false)
    239.             {
    240.                 this.GetComponent<AudioSource>().clip = null;
    241.                 this.GetComponent<AudioSource>().loop = false;
    242.             }        
    243.         }
    244.  
    245.         // disable UI
    246.         if (collider.gameObject.transform.tag == "Page")
    247.             pickUpUI.SetActive(false);
    248.     }
    249. }
    250.  

    Code n
    |



    |
    Error V
    Assets/FreeHorrorGameKit/Scripts/PlayerBehaviour.cs(3,22): error Cs0234: The type or namespace name 'Remoting' does not exist in the namespase 'System.Runtime
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I took a quick look through, and I don't notice anything in this script which uses System.Runtime.Remoting.Messaging. You should probably talk a bit more though than just posting your code and error message without any other information.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,732
    You were here two days ago in a similar unspecified crazy panic:

    https://forum.unity.com/threads/need-help-with-this-important.1091476/#post-7027618

    Please review the steps in the above response to help identify the error and work through it.

    It is possible you don't need that particular
    using
    line and that it was injected automatically by your editor. Rider is particularly insidiously annoying for this.

    Are you using source control in order to identify when that offending line was added?
     
    Joe-Censored likes this.