@Several_SIZE

Unity выдаёт ошибку: 'slenderAI' does not contain a definition for 'position'. Я не понимаю почему, объясните?

Unity выдаёт ошибку: 'slenderAI' does not contain a definition for 'position' and no accessible extension method 'position' accepting a first argument of type 'slenderAI' could be found (are you missing a using directive or an assembly reference?)
Вот такой код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class slenderAI : MonoBehaviour
{
    public Transform dest1, dest2, dest3, player;
    bool teleporting = true;
    public float teleportRate;
    private int randNum;


    void start()
    {
        StartCoroutine(teleport());

    }

    void Update() 
    {
        this.transform.LookAt(new Vector3(player.position.x,this.position.y,player.position.z)); Пишет что ошибка в этой строчке
    }

    IEnumerator teleport()
    {
        while(teleporting == true)
        {
            yield return new WaitForSeconds(teleportRate);
            randNum = Random.Range(0,3);
            if(randNum == 0){
                this.transform.position = dest1.position;
            }
            if(randNum == 1){
                this.transform.position = dest2.position;
            }
            if(randNum == 2){
                this.transform.position = dest3.position;
            }

        }
    }
}

Если в отмеченной строчке убрать player.position.x и player.position.y, то ошибка пропадает. Помогите
  • Вопрос задан
  • 36 просмотров
Пригласить эксперта
Ответы на вопрос 2
WNeZRoS
@WNeZRoS
В указанной строке затесалось this.position.y вместо player.position.y
Ответ написан
@lukwe
можно ещё написать эту строчку вот так
this.transform.LookAt(transform.position);
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы