1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Testing : MonoBehaviour
- {
- public Material transparentMat;
- public Material boneMaterial;
- private GameObject obj;
- private float t;
- // Start is called before the first frame update
- void Start()
- {
- obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
- obj.GetComponent<MeshRenderer>().material = transparentMat;
- LineRenderer lr = obj.AddComponent<LineRenderer>();
- lr.positionCount = 2;
- lr.material = boneMaterial;
- Color line = new Color(1, 1, 1, 0);
- lr.startColor = line;
- lr.endColor = line;
- lr.startWidth = 0.3f;
- lr.endWidth = 0.3f;
- lr.SetPosition(0, obj.transform.position);
- lr.SetPosition(1, new Vector3(1,1,1));
- }
- // Update is called once per frame
- void Update()
- {
- if (t >= 1)
- {
- Destroy(obj);
- return;
- }
-
- t += Time.deltaTime / 2;
- Color newColor = new Color(1, 1, 1, Mathf.Lerp(0, 1, t));
- obj.GetComponent<MeshRenderer>().material.color = newColor;
- obj.GetComponent<LineRenderer>().startColor = newColor;
- obj.GetComponent<LineRenderer>().endColor = newColor;
- }
- }
|