В общем ребята выручайте голова уже не варит, а нужно доделывать. Наверно ответ очень прост, но я его не вижу %)
Нужно проверить столкнулся ли обьект с другим обьектом в классе без MonoBehavior(я отметил в каком месте)
В общем есть код
Код
public class FireMagicClotFire : BaseSpellData, IDamageSpellType
{
private const string SPELL_POINT_NAME = "CreateSpellPoint";//имя обьекта, в позиции которого создаются обьекты заклинаний
private const float VELOCITY = 3.3f;//скорость полета снаряда
private const float DISTANCE = 5f;//дистанция, которую пролетает заклинание
public SpellDamageType SpellDamageType
{
get { return SpellDamageType.FireDamage; }
}
public int Damage { get; set; }//урон наносимый заклинанием
private readonly GameObject _player;//игрок
private readonly GameObject _spellLoadModel;//модель заклинания
private Transform _spellPoint;//точка где создаются обьекты заклинаний
private GameObject _spellObj;//
private Vector3 _starPos;
public FireMagicClotFire()
{
_player = GameObject.FindGameObjectWithTag(ManagerTag.Player);
_spellLoadModel = Resources.Load<GameObject>("MagicSpellObject/FireClotObj") as GameObject;
}
public void Initialization()
{
//поиск обьекта CreateSpellPoint
foreach (var trans in _player.transform.Cast<Transform>().Where(trans => trans.name == SPELL_POINT_NAME))
{
_spellPoint = trans;
Debug.Log(trans.name);
}
if (_spellPoint == null && GeneraGameSetting._GeneraGameSetting.BuildVersion == BuildVersion.Debug)
DebugConsole.Log(string.Format("[FireMagicClotFire] Не найден обьект CreateSpellPoint"), 3);
//создание обьекта
if (_spellPoint != null)
_spellObj = InstantiateObject.InstantiateGameObject(_spellLoadModel, _spellPoint.position, Quaternion.LookRotation(_player.transform.TransformDirection(Vector3.forward)));
_starPos = _spellObj.transform.position;
CoroutineStart.StartCoroutineStatic(GameObject.FindObjectOfType<MonoBehaviour>(), moved(_spellObj));
}
//движение к цели
private IEnumerator moved(GameObject obj)
{
while ((_starPos - obj.transform.position).sqrMagnitude < DISTANCE * DISTANCE)
{
//дебаг луч
Debug.DrawRay(obj.transform.position, obj.transform.TransformDirection(Vector3.forward) * 10, Color.red);
>>>>>>>>>>>>>>>>здесь нужно как то проверку столкновения сделать, что то типа obj.OnCollisionEnter<<<<<<<<<<<<<<<<<<<<
obj.transform.Translate(Vector3.forward * VELOCITY * Time.deltaTime, Space.Self);
yield return null;
}
GameObject.Destroy(obj);
}
}