read a variable from an object in the trigger

Hello everyone
I and a friend are creating a mini-moba, but we have a problem in the script for towers

basically I would like that when a player or a bot comes within range of the tower, it has to read from the script “info” (awarded to the player and bot) belongs to which team the player or the bot, and in case an enemy and points to him.

I created this script helping with the documentation of unity, but I can not solve this problem:

Assets/script/game/torretteB.cs(22,49): error CS1061: Type `UnityEngine.Component' does not contain a definition for `Team' and no extension method `Team' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

this are the script:

using UnityEngine;
using System.Collections;

public class torretteB : MonoBehaviour {

	public int teamID; //0 red team -- 1 Blueteam
	public int teamobject;
	private Vector3 targetpoint =;
	GameObject kObject;
	// Use this for initialization
	void Start () {
		teamID=1;// blueteam

	void OnTriggerEnter(Collider collider)
		if(kObject.GetComponent("info").Team != teamID)
			targetpoint = kObject.gameObject.transform.position;
			Quaternion rotation = Quaternion.LookRotation (targetpoint - transform.position);
			transform.rotation  = rotation;

sorry for my english, I am italian :wink:

GetComponent returns an object of type “Component”. The class “info” that you create is a subclass of Component, so you need to cast the returned object to “info”.

Try something like this:

info infoObj = kObject.GetComponent("info") as info;
if(infoObj.Team != teamID)

Also, class names (info) usually start with a capital letter, and fields (Team) usually start with a lowercase letter.

Edit: Also, the normal C# way of getting components would be easier here since passing the parameterized type will automatically return an “info” instead of a “component”.

if(kObject.GetComponent<info>().Team != teamID)