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. Dismiss Notice

'Component.collider' is obsolete: 'Property collider has been deprecated. Use GetComponent<Collider

Discussion in 'Getting Started' started by whistlinghook2000, May 17, 2020.

  1. whistlinghook2000

    whistlinghook2000

    Joined:
    May 17, 2020
    Posts:
    7
    I keep getting this error and i't not totally sure what it is i need to change?
    Assets\scripts\PlayerController.cs(72,18): error CS0619: 'Component.collider' is obsolete: 'Property collider has been deprecated. Use GetComponent<Collider>() instead. (UnityUpgradable)'
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     public float speed;
    8.     public float JumpPower = 1f;
    9.  
    10.     private Vector3 moveDirection;
    11.     private Rigidbody rb;
    12.     private bool jump;
    13.     private bool isGrounded;
    14.     private Vector3 jumpDirection;
    15.     private Vector3 startPos;
    16.  
    17.     void Start()
    18.     {
    19.         rb = GetComponent<Rigidbody>();
    20.         startPos = rb.position;
    21.  
    22.     }
    23.  
    24.     void Update()
    25.     {
    26.         float moveHorizontal = Input.GetAxis("Horizontal");
    27.         float moveVertical = Input.GetAxis("Vertical");
    28.  
    29.         jump = Input.GetButton("Jump");
    30.  
    31.         moveDirection = new Vector3(moveHorizontal, 0.0f, moveVertical);
    32.     }
    33.  
    34.     void FixedUpdate()
    35.     {
    36.         Move();
    37.         Jump();
    38.     }
    39.     void Move()
    40.     {
    41.         rb.AddForce(moveDirection * speed);
    42.     }
    43.     void Jump()
    44.     {
    45.         LayerMask layer = 1 << gameObject.layer;
    46.         layer = ~layer;
    47.         isGrounded = Physics.CheckSphere(transform.position, 1f, layer);
    48.  
    49.         if (jump && isGrounded)
    50.         {
    51.             rb.AddForce(jumpDirection * JumpPower, ForceMode.Impulse);
    52.         }
    53.     }
    54.     void OnCollisionEnter(Collision collision)
    55.     {
    56.         jumpDirection = collision.contacts[0].normal;
    57.     }
    58.  
    59.  
    60.     void OnTriggerEnter(Collider other)
    61.     {
    62.         if (other.gameObject.CompareTag("Pick Up"))
    63.         {
    64.             other.gameObject.SetActive(false);
    65.  
    66.  
    67.  
    68.             rb.position = startPos;
    69.             rb.velocity = Vector3.zero;
    70.             rb.angularVelocity = Vector3.zero;
    71.         }
    72.         else if (collider.gameObject.CompareTag("Gameover")) ;
    73.  
    74.                 }
    75.     }
    76.  
     
  2. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    Well you have it correct in line #62 but wrong in #72. Try;

    Code (CSharp):
    1. else if (other.gameObject.CompareTag("Gameover")) ;
     
  3. whistlinghook2000

    whistlinghook2000

    Joined:
    May 17, 2020
    Posts:
    7
    i managed to get it working but now i have the error Gameover tag is not defined although i created a tag called Gameover and assigned it to an object upload_2020-5-18_19-15-8.png