Question by
ThomasAqtl · Sep 09, 2021 at 09:05 PM ·
c#editormaterial
Scaling a plane in ExecuteAlways mode removes color
Hello everyone,
I'm having an issue when scaling an object with an [ExecuteAlways] script. Here is the script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteAlways]
public class Surface : MonoBehaviour {
private GameObject plane;
[Header("Dimensions")]
[SerializeField] [Range(1, 100)] private float length;
[SerializeField] [Range(1, 100)] private float width;
private void Start() {
plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.transform.localPosition = Vector3.zero;
}
private void Update() {
UpdateDimensions();
}
// Divides by 10 because a plane with scale 1 is 10 unit squared
public void UpdateDimensions() {
plane.transform.localScale = new Vector3(length, 0, width) / 10.0f;
}
}
So, whenever I use the slider on length and width value, the scales is actually changed. But the color turns black and I do not understand why. Here is a gif to show you :
Why does the plane is black ? Thanks in advance.
Regards
exemple4.gif
(504.5 kB)
Comment
Your answer
Follow this Question
Related Questions
How to Place currently selected tiles in the editor 0 Answers
How do I modify a 'Specific' Material in my gameObject's Renderer? 0 Answers
Custom Inspector for a list of custom class members. 2 Answers
Scene not loading in game tab but works when built?? 0 Answers
Entering PlayMode execution order 2 Answers