|
I have a problem with my prefab. I import my model and created a prefab "Player". Again i did the same step to the "Enemy", but i need check the distance of player with enemy and when i use Vector3 D = player.position - tranform.position(script attached in enemy) it check the prefab position and not the gameObject in scene. Then i use it Player = GameObject.FindWithTag("Player").transform; and work with player.... but my "Enemy" is several equal in scene, and i not instantiate them. It is fixed before. They have a function that does count in a variable "Player" and one bool variable. Basically when comes to near of enemy, it count a alert, and enable a GUI placed on player script. What i need? I need a solution for them to function independent. Here my enemy script. using UnityEngine; public class CDA_01 : MonoBehaviour { } Here part of player script [RequireComponent(typeof(CharacterController))] public class MyPerson : MonoBehaviour { }
(comments are locked)
|
|
You're assigning the Player to the variable enemy, thus the distance between the player and the enemy will always be zero. You don't need to find the enemy in its own script: just use the property transform:
...
private Transform enemy;
MyPerson scriptPlayer;
public void Start()
{
scriptPlayer = GameObject.FindWithTag("Player").GetComponent< MyPerson>();
enemy = transform; // this object is the enemy, thus just get its transform
}
...
My problem is similar it http://answers.unity3d.com/questions/245542/need-help-understanding-scripted-prefab-behavior-w.html I need to controll the prefabs independently...
May 10 '12 at 08:44 PM
HausLord
Olá! vi sua pagina e você é de São Paulo. Também sou, tem como você me passar seu contato pra poder me ajudar? esse meu problema é de um trabalho para faculdade! Obrigado.
May 10 '12 at 09:00 PM
HausLord
(comments are locked)
|
|
Yes, it worked, but i need show my GUI. My GUI showed when i stay near the enemy, but it isnt worked. My GUI just showed in near the first enemy prefab on scene. If im move to third enemy prefab, the variable countAlert works and GUI not. What i want to do? If i stay near 1 enemy prefab, show GUI and countAlert. If i stay near 2 enemy prefab, my countAlert x2 and show GUI, but independent of which of prefabs, everyone has to count and everyone has to show GUI. note: i use the variable nearToCDA for show and hide the GUI.
(comments are locked)
|
