J'essaye de détecter l'objet le plus proche du joueur à partir de son nom.
Je n'y arrive pas, j'ai commencé à écrire un script :
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NearedZombie : MonoBehaviour
{
private float dist;
private float mindist;
public GameObject goodhumain;
void start()
{
}
void Update()
{
mindist = 1000f;
if (gameObject!= null)
{
foreach (GameObject human in GameObject.FindObjectsOfType(typeof(GameObject)))
{
if (human.name == "CaucasianMale")
{
dist = Vector3.Distance(human.position, gameObject.position);
if (dist < mindist)
{
mindist = dist;
goodhuman = human;
}
}
}
if (Input.GetKey((KeyCode)PlayerPrefs.GetInt("follow")))
{
goodhuman.setFollowMe();
}
}
}
}
Assets/Scripts/NearedZombie.cs(26,51): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `position' and no extension method `position' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?
Assets/Scripts/NearedZombie.cs(26,72): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `position' and no extension method `position' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?
Assets/Scripts/NearedZombie.cs(30,25): error CS0103: The name `goodhuman' does not exist in the current context
Assets/Scripts/NearedZombie.cs(36,17): error CS0103: The name `goodhuman' does not exist in the current context
Je veux bien un peu d'aide...
De plus l'objet que j'essaye de détecter n'ai pas présent sur la scène au départ.