Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Need help with errors

Discussion in 'Scripting' started by Ryuso_, Apr 26, 2020.

  1. Ryuso_

    Ryuso_

    Joined:
    Nov 30, 2019
    Posts:
    9
    I am following a tutorial to make a portal gun
    ) had found a few errors, after fixing those I got 7 errors, I am using Unity 2017.4.39f1. Any help would be greatly appreciated!!
    The errors are:

    error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `getComponent' and no extension method `getComponent' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?

    error CS1061: Type `UnityEngine.Quaternion' does not contain a definition for `eulerangles' and no extension method `eulerangles' of type `UnityEngine.Quaternion' could be found. Are you missing an assembly reference?

    error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

    error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `getComponent' and no extension method `getComponent' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?

    error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `getComponent' and no extension method `getComponent' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?

    error CS1061: Type `UnityEngine.Transform' does not contain a definition for `game' and no extension method `game' of type `UnityEngine.Transform' could be found. Are you missing an assembly reference?

    error CS1061: Type `System.Collections.Generic.List<objectPortal>' does not contain a definition for `count' and no extension method `count' of type `System.Collections.Generic.List<objectPortal>' could be found. Are you missing an assembly reference?

    The code is:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityStandardAssets.Characters.FirstPerson;
    5. public class PortalManager : MonoBehaviour
    6. {
    7.  
    8. [SerializeField]
    9. private Portal firstPortal;
    10.  
    11. [SerializeField]
    12. private Portal secondPortal;
    13.  
    14. [SerializeField]
    15. private Transform playerCam;
    16.  
    17. private float magnitude;
    18.  
    19. private Vector3 velocity;
    20.  
    21. private RaycastHit hit;
    22.  
    23. [SerializeField]
    24. private LayerMask rayMask;
    25.  
    26. private List<objectPortal> currentObjects = new List<objectPortal>();
    27.  
    28.     // Start is called before the first frame update
    29.     void Start()
    30.     {
    31.      
    32.     }
    33.  
    34.     // Update is called once per frame
    35.     void Update()
    36.     {
    37.      
    38.     }
    39.  
    40. public void PortalObject(bool isFirstPortal, GameObject currentObj)
    41. {
    42.     objectPortal objectToCheck = GetObjectPortalByGameObject(currentObj);
    43.  
    44.     if(currentObjects.Contains(objectToCheck))
    45.     {
    46.         if(isFirstPortal && objectToCheck.currentPortal == firstPortal)
    47.         return;
    48.  
    49.         if (!isFirstPortal && objectToCheck.currentPortal == secondPortal)
    50.         return;
    51.  
    52.         currentObjects.Remove(objectToCheck);
    53.     }
    54.  
    55.     Rigidbody tempRidgid = currentObj.getComponent<Rigidbody>();
    56.  
    57.     Vector3 pos = Vector3.zero;
    58.     Vector3 rot = Vector3.zero;
    59.  
    60.     magnitude = tempRidgid.velocity.magnitude;
    61.  
    62.     objectPortal newObject = new objectPortal();
    63.  
    64.     Portal newPortal = firstPortal;
    65.  
    66.     if(!isFirstPortal)
    67.         newPortal = secondPortal;
    68.  
    69.     pos = newPortal.transform.position;
    70.  
    71.     if(!newPortal.gameObject.activeSelf)
    72.         return;
    73.  
    74.     rot = newPortal.transform.rotation.eulerangles;
    75.     velocity = newPortal.transform.forward;
    76.  
    77.     newObject.currentPortal = newPortal
    78.     ;
    79.     newObject.currentGameObject = currentObj;
    80.  
    81.     currentObjects.Add(newObject);
    82.  
    83.     tempRidgid.velocity - Vector3.zero;
    84.  
    85.     if(currentObj.layer == 8)
    86.         pos +=  newPortal.transform.forward * 1.3f;
    87.  
    88.     currentObj.transform.position = pos;
    89.  
    90.     if(currentObj.layer == 8)
    91.     {
    92.         currentObj.getComponent<RigidbodyFirstPersonController>().mouseLook.m_CharacterTargetRot = Quaternion.Euler(new Vector3(0,rot.y,0));
    93.         currentObj.getComponent<RigidbodyFirstPersonController>().movementSettings.CurrentTargetSpeed = magnitude;
    94.     }
    95.     else
    96.     {
    97.         currentObj.transform.rotation = Quaternion.Euler(rot);
    98.      
    99.     }
    100.         tempRidgid.AddForce(velocity * magnitude, ForceMode.VelocityChange);
    101.  
    102.         StartCoroutine("RemoveObject", newObject);
    103.  
    104.     }
    105.  
    106.     public void SetPortal(Portal currentPortal)
    107.     {
    108.         if(Physics.Raycast(playerCam.position, playerCam.forward, out hit, 100, rayMask))
    109.         {
    110.             if(hit.transform.game.Object.layer == 17)
    111.                 return;
    112.  
    113.             currentPortal.gameObject.SetActive(true);
    114.  
    115.             currentPortal.transform.position = hit.point;
    116.  
    117.             currentPortal.transform.rotation = Quaternion.LookRotation(hit.normal);
    118.  
    119.         }
    120.     }
    121.  
    122.     public IEnumerator RemoveObject(objectPortal removeObjectPortal)
    123.         {
    124.             yield return new WaitForSeconds(0.1f);
    125.  
    126.             if(!currentObjects.Contains(removeObjectPortal))
    127.             yield break;
    128.  
    129.             currentObjects.Remove(removeObjectPortal);
    130.         }
    131.  
    132.         public objectPortal GetObjectPortalByGameObject (GameObject objectToCheck)
    133.         {
    134.             for (int i = 0; i < currentObjects.count; i++)
    135.             {
    136.                 if(currentObjects[i].currentGameObject == objectToCheck)
    137.                     return currentObjects[i];
    138.             }
    139.  
    140.             return new objectPortal();
    141.  
    142.         }
    143. }
    144.  
    145. [System.Serializable]
    146. public struct objectPortal
    147. {
    148.     public Portal currentPortal;
    149.     public GameObject currentGameObject;
    150. }
    151.  
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Spelling is very important in programming. You really need to pay attention there.
    • 'getComponent' does not exist, but 'GetComponent' does
    • 'eulerangles' does not exist, but 'eulerAngles' does
    • 'game' does not exist and i'm not sure what you means, but probably 'gameObject'
    • 'count' does not exist but 'Count' does
    All of these identifiers follow naming conventions. Variables are wrriten in 'camelCase', while method, class and property names are written in 'UpperCamelCase'. This helps differentiating, for example, a variable from a method or property.
     
  3. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    488
    It's not "getComponent", it's "GetComponent". C# is case sensitive, therefore, you must write everything EXACTLY as you see it in the video. Most of your errors are due to this
     
  4. Ryuso_

    Ryuso_

    Joined:
    Nov 30, 2019
    Posts:
    9
    Ahh, thank you, I didn't realise that he had added capitals, thanks again!!
     
  5. Ryuso_

    Ryuso_

    Joined:
    Nov 30, 2019
    Posts:
    9
    Ahh, I didn't realise he added capitals, thank you!