I have to make an object shoot a raycast and when this this raycast hit another object that has the name "notices. This object will be highlighted. When that object is highlighted, when i click a button on the keyboard, the object will be destroyed.
Can you help me make it destroy?
void Start()
{
highlightColor = Color.green;
}
// Update is called once per frame
void Update()
{
RaycastHit hit;
Renderer currRend;
Debug.DrawRay(transform.position, this.transform.forward * Range, Color.magenta);
if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, Range))
{
if (hit.collider.gameObject.name == "Notices")
{
currRend = hit.collider.gameObject.GetComponent<Renderer>();
if (currRend == rend)
return;
if (currRend && currRend != rend)
{
if (rend)
{
rend.sharedMaterial = originalMaterial;
}
}
if (currRend)
rend = currRend;
else
return;
if (hit.collider.gameObject.name == "Notices" == currRend)
{
Debug.Log("dsfvg");
if (Input.GetKeyDown("1"))
{
Debug.Log("asd");
Destroy(gameObject);
}
}
originalMaterial = rend.sharedMaterial;
tempMaterial = new Material(originalMaterial);
rend.material = tempMaterial;
rend.material.color = highlightColor;
}
else
{
}
}
}
} `
Aucun commentaire:
Enregistrer un commentaire