Trying to make an object invisible while hovering..

hey there,
me and a mate are trying to make an object invisible just while hovering,
there must be a mistake in the code.
we tried our best but we did not figure it out.

please help!
thanks a lot!!!

ps.: the 0f actually should be changed into a 0.5f but it doesn’t work either… it should be only slightly invisible

using UnityEngine;
using System.Collections;

public class Invisible : MonoBehaviour
{
    private Color initialColor; 

    void Start()
    {
        initialColor = renderer.material.color;
    }
    
    void OnMouseOver()
    {
        renderer.material.color = new Color(initialColor.r, initialColor.g, initialColor.b, 0f);
    }

    void OnMouseExit()
    {
        renderer.material.color = initialColor;
    }
}

Make sure there is a Collider (or RigidBody) on the object. Can be ‘trigger’ if you don’t want to actually collide with it.

Your code looks fine. Best guess is that this is a shader issue. Your code will only work if the shader supports transparency and has a main color attribute. As a starting point, use the Transparent/Diffuse shader. And as @DavidA indicates, the object must have a collider, and that collider must be topmost. If you have other colliders in the way, it will not work.