Testing.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Testing : MonoBehaviour
  5. {
  6. public Material transparentMat;
  7. public Material boneMaterial;
  8. private GameObject obj;
  9. private float t;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
  14. obj.GetComponent<MeshRenderer>().material = transparentMat;
  15. LineRenderer lr = obj.AddComponent<LineRenderer>();
  16. lr.positionCount = 2;
  17. lr.material = boneMaterial;
  18. Color line = new Color(1, 1, 1, 0);
  19. lr.startColor = line;
  20. lr.endColor = line;
  21. lr.startWidth = 0.3f;
  22. lr.endWidth = 0.3f;
  23. lr.SetPosition(0, obj.transform.position);
  24. lr.SetPosition(1, new Vector3(1,1,1));
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. if (t >= 1)
  30. {
  31. Destroy(obj);
  32. return;
  33. }
  34. t += Time.deltaTime / 2;
  35. Color newColor = new Color(1, 1, 1, Mathf.Lerp(0, 1, t));
  36. obj.GetComponent<MeshRenderer>().material.color = newColor;
  37. obj.GetComponent<LineRenderer>().startColor = newColor;
  38. obj.GetComponent<LineRenderer>().endColor = newColor;
  39. }
  40. }