Je cherche a mettre en evidence des objects lorsque je m'approche d'eux. J'ai donc trouvé QuickOutline sur l'assets store.
Il fait exactement ce que je cherche sauf quie je seche sur un problème depuis pas mal d'heures...
Code : Tout sélectionner
void highlight()
{
if(Physics.Raycast(cam.transform.position,cam.transform.TransformDirection(Vector3.forward),out RaycastHit hit, Mathf.Infinity)) //lance le rayon vers le premier objet touché
{
if (isDebugLog) Debug.Log("Distance " + hit.transform.gameObject.name + " visé " + RoundValue(hit.distance,1)+ " Layer: "+hit.transform.gameObject.layer);
//Si l'objet est taggé "surbrillance" et et a une disatnce inférieur a la variable "highlightDistance" et a le layer "highlightLayer"
//if (hit.transform.gameObject.tag == "Surbrillance" && hit.distance < highlightDistance && hit.transform.gameObject.layer == highlightLayer)
if (hit.transform.gameObject.tag == "Surbrillance" && hit.distance < highlightDistance)
{
hittedObject = hit.transform.gameObject;
if (isDebugLog) Debug.Log("Objet trouvé " + hittedObject.name+" Distance= "+ RoundValue(hit.distance, 1));
hittedObject.GetComponent<Outline>().enabled = true;
}
else
{
hittedObject.GetComponent<Outline>().enabled = false;
if (isDebugLog) Debug.Log("Sinon " + hittedObject.name);
hittedObject = null;
}
if (actionInputValue && hittedObject != null && hittedObject.name == "Sphere")
{
if (isDebugLog) Debug.Log("Détruire l'objet visé " + hittedObject.name);
Destroy(hittedObject); //effacer l'objet
}
}
}
Je pense comprendre qu'il n'y a pas de valeur sur cette variable après avoir était réinitialisé mais je ne sais pas comment gérer ça ! J'ai essayer plein de chose mais je me suis un peu perdu...
Au secours !
UnassignedReferenceException: The variable hittedObject of Interaction has not been assigned.
You probably need to assign the hittedObject variable of the Interaction script in the inspector.
UnityEngine.GameObject.GetComponent[T] () (at <4746c126b0b54f3b834845974d1a9190>:0)
Interaction.highlight () (at Assets/Scripts/Interaction.cs:59)
Interaction.Update () (at Assets/Scripts/Interaction.cs:38)