Answers for "make something transparent unity"

C#
1

unity transparent object

//For 2D sprites :
public GameObject myObject;

public void makeTransparent()
{
  var col = myObjetc.GetComponent<SpriteRenderer>().color;
  col.a = 0.5f; //Change the value of transparency here (with 0 = totally transparent and 1 = not transparent at all)
  myObjetc.GetComponent<SpriteRenderer>().color = col;
}

//For 3D gameObjects :
I think you have to use shaders there are a lot of youtube videos it is not only with a script
Posted by: Guest on April-18-2021
0

How to make game object transparent in unity

GameObject g;

// 50% Transparency.
g.renderer.material.color.a = 0.5f; // a is the alpha value.

 // 100% Transparency.
g.renderer.material.color.a = 1.0f;
Posted by: Guest on July-01-2021
0

unity transparent game

using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Transparency : MonoBehaviour
{
    
    [DllImport("user32.dll")]
    public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type);

    [DllImport("user32.dll")]
    private static extern IntPtr GetActiveWindow();

    [DllImport("user32.dll")]
    private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

    [DllImport("user32.dll", SetLastError = true)]
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

    [DllImport("user32.dll")]
    static extern int SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

    private struct MARGINS {
        public int cxLeftWidth;
        public int cxRightWidth;
        public int cyTopHeight;
        public int cyBottomHeight;
    }
    [DllImport("Dwmapi.dll")]
    private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);

    const int GWL_EXSTYLE = -20;

    const uint WS_EX_LAYERED = 0x00080000;
    const uint WS_EX_TRANSPARENT = 0x00000020;

    static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);

    const uint LWA_COLORKEY = 0x00000001;
    
    private void Start() {
        
#if !UNITY_EDITOR        
        IntPtr hWnd = GetActiveWindow();
        
        MARGINS margins = new MARGINS { cxLeftWidth = -1 };
        DwmExtendFrameIntoClientArea(hWnd, ref margins);

        SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED);
        SetLayeredWindowAttributes(hWnd, 0, 0, LWA_COLORKEY);

        SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, 0);
#endif        
    }


}
Posted by: Guest on June-27-2021

Code answers related to "make something transparent unity"

C# Answers by Framework

Browse Popular Code Answers by Language