API updating script cause them to no longer work.

I am working through the tutorials to increase my level of knowledge of unity, but I am running into issue on some of them saying "the project contains scripts that use obsolete API. When I do they update the script doesn’t function. Can someone look at this code and help me out?

before update API:

using UnityEngine;
using System.Collections;

public class Resetter : MonoBehaviour {
  
   public Rigidbody2D projectile;
   public float resetSpeed = 0.025f;
   
   private float resetSpeedSqr;
   private SpringJoint2D spring;
   
   
   void Start () {
     resetSpeedSqr = resetSpeed * resetSpeed;
     spring = projectile.GetComponent <SpringJoint2D>();
     
   }
   
   
   void Update () {
     if(Input.GetKeyDown (KeyCode.R)) {
       Reset();
     }
     if(spring == null && projectile.velocity.sqrMagnitude < resetSpeedSqr){
       Reset();
     }
     
   }
   
   void OntriggerExit2D (Collider2D other){
     if (other.rigidbody2D == projectile){
       Reset();
     }
   }
   void Reset () {
     Application.LoadLevel (Application.loadedLevel);
   }
}

After API update

using UnityEngine;
using System.Collections;

public class Resetter : MonoBehaviour {
   public Rigidbody2D projectile;
   public float resetSpeed = 0.025f;
   
   private float resetSpeedSqr;
   private SpringJoint2D spring;
   
 void Start () {
     resetSpeedSqr = resetSpeed * resetSpeed;
     spring = projectile.GetComponent <SpringJoint2D>();
     
   }
   
   void Update () {
     if(Input.GetKeyDown (KeyCode.R)) {
       Reset();
     }
     if(spring == null && projectile.velocity.sqrMagnitude < resetSpeedSqr){
       Reset();
     }
     
   }
   
   void OntriggerExit2D (Collider2D other){
     if (other.GetComponent<Rigidbody2D>() == projectile){
       Reset();
     }
   }
   void Reset () {
     Application.LoadLevel (Application.loadedLevel);
   }
}

Try other.gameObject.getcomponent instead of other.getcomponent

  • void OntriggerExit2D (Collider2D other){
  • if (other.GetComponent() == projectile){
  • Reset();
  • }

to this?

[LIST=1]
[*] void OntriggerExit2D (Collider2D other){
[*]     if (other.gameObject.getcomponent<Rigidbody2D>() == projectile){
[*]       Reset();
[*]     }
[/LIST]

??

Yeah

Or simply let the getcomponent part out, if you store the projectile variable as a gameobject

void OntriggerExit2D (Collider2D other){
if (other.gameObject.getcomponent<Rigidbody2D>() == projectile){
  Reset();
}

didn’t work. I think I am giving up. Sad when the tutorials for the product don’t work.

First of all, GetComponent, not getcomponent, secondly, let the whole thing out, simply do other.gameObject

Edit.: wait, did you assign the projectile to the variable?