Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LineRendererTest1-2 : MonoBehaviour {
private LineRenderer lr;
private Renderer rn;
void Start () {
lr = GetComponent<LineRenderer>();
lr.SetVertexCount(4);
lr.SetWidth(0.2f,0.2f);
lr.SetPosition(0,new Vector3(-7.0f,-2.0f,25.0f));
lr.SetPosition(1,new Vector3(14.0f,-2.0f,25.0f));
lr.SetPosition(2,new Vector3(-7.0f,-2.0f,25.0f));
lr.SetPosition(3, new Vector3(-7.0f,15.0f,25.0f));
rn = GetComponent<Renderer>();
// colorの範囲は0-1.0f。 ただし、Inspectorでは0-255で表示される
rn.material.SetColor("_Color",new Color(1.0f,0.0f,0.0f,1)); //R,G,B = 255,0,0,255に相当
//これを追加すると、Emissionの色を指定できる
rn.material.SetColor("_EmissionColor",new Color(1.0f,0.0f,0.0f));
//もしこのように書くと、Emissionが入ったような色表示になる。実行はできるがconsoleにはエラーが出る
/*
*Invalid normalized color: RGBA(255.000, 0.000, 0.000, 255.000), normalize value: 0 UnityEditor.DockArea:OnGUI()
*/
//rn.material.SetColor("_Color",new Color(255,0,0,255));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment