[英]every time i try to test run i run in to an error The name 'Player' does not exist in the current context. i cant find a solution
I am making a game and in the game im trying to make the enemy go towards the player when the player steps into the sight of the enemy.我正在制作一个游戏,在游戏中,当玩家进入敌人的视线时,我试图让敌人走向玩家。 I cant figure out how to make the name (player) mean anything im very new at this its my second attempt on makin a game please help me im very confused im running c#
我不知道如何让这个名字(玩家)意味着任何我很新的东西这是我第二次尝试制作游戏请帮助我我很困惑我正在运行 c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
private Transform _target;
[SerializeField] private float _speed = 9;
void Awake() {
_target = FindObjectOfType(Player)().transform;
}
void update() {
transform.position = Vector3.MoveTowards(transform.position,_target.position, _speed * Time.deltaTime);
}
}
You need to use the typeof
operator instead of passing the class name.您需要使用
typeof
运算符而不是传递类名。
void Awake() {
_target = FindObjectOfType(typeof(Player))().transform;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.