hello I have a great problem, yesterday my code work and nom I don’t have un test print…
my code:
entityGlobal:
public class Entity : MonoBehaviour {
int moveSpeed = 3; //move speed
int rotationSpeed = 3; //speed of turning
public float range = 10f;
float farPos = 15f;
public float stop = 0.05f;
Transform myTransform; //current transform data of this enemy
public float distance; //rotate to look at the player
public Transform player; //the enemy's target
public EntityTest entityTest;
void Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
void Start()
{
player = GameObject.FindWithTag("Player").transform; //target the player
entityTest = gameObject.GetComponent<EntityTest> ();
}
void Update(){
CheckComponents ();
}
void profanateur(){
print ("profanateur");
}
void protecteur(){
print ("protecteur");
}
void enemy(){
print ("enemy");
FollowEnemy ();
}
void neutral(){
print ("neutral");
}
void amical(){
print ("amical");
}
void servant(){
print ("larbin");
FollowAmical ();
}
void CheckComponents(){
if (GetComponent<EntityTest>()) {
print("test");
Entity entity = GetComponent<Entity>();
entity.servant();
}
}
void FollowAmical () {
distance = Vector3.Distance(myTransform.position, player.position);
if(distance<=range && distance>=stop){
//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(player.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
if (distance >= farPos) {
myTransform.position = player.transform.position;// ce code modifie la valeur de l'entitée a celle du player
}
}
void FollowEnemy () {
distance = Vector3.Distance(myTransform.position, player.position);
if(distance<=range && distance>=stop){
//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(player.position - myTransform.position), rotationSpeed*Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
and code on my entity:
public class EntityTest : MonoBehaviour {
public static int health = 100;
public Entity entity;
public bool isAlive = true;
// Use this for initialization
void Start () {
entity = gameObject.GetComponent<Entity> ();
}
// Update is called once per frame
void Update () {
Component ();
//IsDead ();
}
void Component(){
if (GetComponent<Entity> ()) {
print ("Entity detected");
}
}
}
the print “test” was not print, the print “Entity Detected” too…
the problem is in the condition: if (GetComponent()) and if (GetComponent ())