Search Unity

Hey I tried to get an int from another script but there is an error! Please help :)

Discussion in 'Scripting' started by EmotionIce, Dec 29, 2016.

  1. EmotionIce

    EmotionIce

    Joined:
    Nov 16, 2016
    Posts:
    20
    Hey the error is in line #27.
    Error:
    error CS0246: The type or namespace name `playerScript' could not be found. Are you missing a using directive or an assembly reference?

    Please help me and I would be very happy if if someone could repair the error and send the script back.
    Thanks for every answer.
    btw. sorry for bad grammar because I am german.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Score : MonoBehaviour
    5. {
    6.     //booleans
    7.     public bool isCounting = true;
    8.     public bool showScoreInTheMiddle;
    9.     public bool takeScore;
    10.     public bool scoreIsTakable;
    11.     public bool upgradable;
    12.     public bool notEnoughPointsGUI;
    13.     public bool showGUI;
    14.     public bool showHealthOnScreen;
    15.  
    16.     // numbers
    17.     public float notEnoughPointsGUIShowCounter;
    18.     public float timer;
    19.     public int requiredPoints;
    20.     public int healthInThisScript;
    21.     public int score;
    22.     public int upgradePoints;
    23.     public int hiScore;
    24.     private GUIStyle guiStyle = new GUIStyle();
    25.     public GameObject DethScreen;
    26.  
    27.     public playerScript pScript; //Here is the error!! The errorcode is: error CS0246: The type or namespace name `playerScript' could not be found. Are you missing a using directive or an assembly reference?
    28.  
    29.     void Start()
    30.     {
    31.         RetrievePlayerPrefs();
    32.         scoreIsTakable = true;
    33.         takeScore = false;
    34.         GameObject kugel = GameObject.Find("Kugel");
    35.         // KugelCollider = scriptname
    36.  
    37.         KugelCollider kugelCollider = kugel.GetComponent<KugelCollider>();
    38.     }
    39.     void Update()
    40.     {
    41.         if (isCounting)
    42.         {
    43.             Counting();
    44.         }
    45.         if (DethScreen.activeInHierarchy)
    46.         {
    47.             isCounting = false;
    48.             takeScore = true;
    49.             showHealthOnScreen = true;
    50.         }
    51.         else
    52.         {
    53.             showHealthOnScreen = false;
    54.         }
    55.  
    56.         if (takeScore == true)
    57.         {
    58.             if (scoreIsTakable == true)
    59.             {
    60.                 upgradePoints = upgradePoints + score;
    61.                 scoreIsTakable = false;
    62.             }
    63.         }
    64.         //I got the tip to assign health to the specific instance of the script (I think I have to do it in the Inspector but because of the error it doesnt work to assign it)
    65.         pScript.health = healthInThisScript;
    66.         if (upgradePoints >= requiredPoints)
    67.         {
    68.             upgradable = true;
    69.         }
    70.         else
    71.         {
    72.             upgradable = false;
    73.         }
    74.  
    75.         UpdatePlayerPrefsPoints();
    76.  
    77.         if (score > hiScore)
    78.         {
    79.             UpdatePlayerPrefsHighScore();
    80.         }
    81.  
    82.         if (DethScreen.activeInHierarchy)
    83.         {
    84.             showScoreInTheMiddle = true;
    85.         }
    86.  
    87.         if (notEnoughPointsGUI == true)
    88.         {
    89.             notEnoughPointsGUIShowCounter += 1f;
    90.             showGUI = true;
    91.             notEnoughPointsGUI = false;
    92.         }
    93.         else
    94.         {
    95.             notEnoughPointsGUIShowCounter = 0;
    96.         }
    97.  
    98.         if (notEnoughPointsGUIShowCounter >= 3)
    99.         {
    100.             showGUI = false;
    101.         }
    102.     }
    103.  
    104.     void Counting()
    105.     {
    106.         timer += Time.deltaTime;
    107.         if (timer > 1f)
    108.         {
    109.             score += 1;
    110.             timer -= 1f;
    111.         }
    112.     }
    113.     void RetrievePlayerPrefs()
    114.     {
    115.         hiScore = PlayerPrefs.GetInt("HighScore");
    116.         requiredPoints = PlayerPrefs.GetInt("requiredPoints");
    117.         upgradePoints = PlayerPrefs.GetInt("upgradePoints");
    118.     }
    119.  
    120.     void UpdatePlayerPrefsHighScore()
    121.     {
    122.         hiScore = score;
    123.         PlayerPrefs.SetInt("HighScore", hiScore);
    124.     }
    125.  
    126.     public void UpgradeHealthButton()
    127.     {
    128.         if (upgradable == true)
    129.         {
    130.             requiredPoints = requiredPoints * 2;
    131.             healthInThisScript += 10;
    132.             upgradePoints = upgradePoints - requiredPoints;
    133.         }
    134.         else
    135.         {
    136.             notEnoughPointsGUI = true;
    137.         }
    138.     }
    139.  
    140.     // OLD OnGUI SYSTEM!
    141.     // CONSIDER CHANGING TO NEW UI SYSTEM.
    142.     // - BUT HOW???
    143.     void OnGUI()
    144.     {
    145.         guiStyle.fontSize = 60;
    146.         GUI.Label(new Rect(105, 22, 100, 100), score.ToString(), guiStyle);
    147.         GUI.Label(new Rect(205, 22, 100, 100), hiScore.ToString(), guiStyle);
    148.         if (showScoreInTheMiddle == true)
    149.         {
    150.             GUI.Label(new Rect(515, 290, 100, 100), score.ToString(), guiStyle);
    151.         }
    152.  
    153.         if (showHealthOnScreen == true)
    154.         {
    155.             GUI.Label(new Rect(105, 22, 100, 100), pScript.health.ToString(), guiStyle);
    156.             GUI.Label(new Rect(105, 22, 100, 100), upgradePoints.ToString(), guiStyle);
    157.         }
    158.     }
    159. }
    160.  
    161. //I would be very happy if someone could repair the error and send the script back; THX
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,175
    Do you have a class called playerScript?
    (BTW, if yes, class should start with an uppercase)
     
  3. EmotionIce

    EmotionIce

    Joined:
    Nov 16, 2016
    Posts:
    20
    no but I have a class called Player and if I change the "playerScript" in the script (line 27) to player - still the same error
     
  4. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,175
    Did you pay attention to capital letter?
     
  5. EmotionIce

    EmotionIce

    Joined:
    Nov 16, 2016
    Posts:
    20
    I tried both with uppercase and lowercase letters
     
  6. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,175
    One question, how much did you use C# before attemting unity?
     
  7. EmotionIce

    EmotionIce

    Joined:
    Nov 16, 2016
    Posts:
    20
    i didnt :D
     
  8. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,175
    Then go ahead and learn it, you really shouldn't start with unity.
    Visit this site: learncs.org
     
unityunity