GetComponent().transform

Hi again,
I’m trying to convert a java script from a tutorial to C# code. Here’s the code that I’m trying to convert.

var switchToTarget : Transform;
function Update () {
if (Input.GetButtonDown("Jump"))
GetComponent(Follow).target = switchToTarget;
}

Here’s the C# code that I’ve converted.

using UnityEngine;
using System.Collections;

public class SwitchC : MonoBehaviour {

	public Transform switchToTarget;	
	
	void Update () {
		if(Input.GetButtonDown("Jump")){
			GetComponent(Follow2).target = switchToTarget;
		}	
	}
}

I don’t know what’s wrong. May be I overlooked something. Any suggestion’s appreciated.

Cheers,
Desmond

your problem is that GetComponent does return a behavior, it does not return a behavior of your specific class, you need to cast it for this purpose.

also, its typeof(Classname) not Classname you need to search for