If you do the color change process (material.color) in Update(), it somehow goes through.

Asked 1 years ago, Updated 1 years ago, 41 views


as follows: If you change the color in Start(), you can do it.

If you do it in Update(), it will go through and you will not be able to handle it.
By the way, I was able to get the location.

Also, when I got the color information, Debug.Log was able to get it with the color changed.
However, the results (screen) remained the same color.

If anyone understands, please let me know.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class BattleMain: BattleBase {

    protected int_sceneTask;
    // public GameObject prefab=(GameObject)Resources.Load("Object/MassTile");
    publicGameObject prefab=null;
    public GameObject[,] pass = new GameObject[15,15];
    intisk;
    intjsk;
    // Use this for initialization
    void Start() {

        // Load prefabricated to place 
        // GameObject prefab=(GameObject)Resources.Load("Object/MassTile");
        // Specify the object from which to place it 
        GameObject stageObject=GameObject.FindWithTag("Stage");
        //// tile arrangement
        for(inti=0;i<15;i++){
            for(int j=0;j<15;j++){


                Vector3tile_pos = new Vector3(
                    0+prefab.transform.localScale.x*i,
                    0,
                    0+prefab.transform.localScale.z*j

                    );

                if(prefab!=null){
                    // prefabricated replication 
                    GameObject instant_object = Instantiate(prefab, tile_pos, Quaternion.identity) as GameObject;
                    // attach a replicated prefabricated under the generator 
                    instant_object.transform.parent=stageObject.transform;
                    pass[i,j] = instant_object;
                }
            }
        }
        int Event=Random.Range(4,7); // Install event mass at random
        for(intp=0;p<Ivent;p++){
        intiRandNum=Random.Range(0,14);
        int jRandNum = Random.Range(0,14);
        mass[iRandNum,jRandNum].GetComponent<Render>().material.color=newColor(0.2f,0.8f,0.9f,0.5f);
        }


    }


    // Update is called once per frame

    void Update() {
        mass[5,5].GetComponent<Render>().material.color=newColor(0.0f,0.0f,0.0f);
        Debug.Log(pass[5,5].GetComponent<Render>().material.color);
        class[1,5].GetComponent<Render>().material.color=newColor(0.2f, 0.8f, 0.9f, 0.5f);
        Debug.Log(pass[1,5].GetComponent<Render>().material.color);
    }


}

Enter a description of the image here

Enter a description of the image here

unity3d

2022-09-29 21:46

1 Answers

As for Unity 5.3.1, the 5 and 5 position squares have turned black as intended.
Do you happen to have more than one BattleMain attached to the same object?

this.btm=this.gameObject.GetComponent<BattleMain>();

This description is strange and should normally be this.btm==this.
As a trial, will ↓ work with this?

void Update(){
//    btm.SyuIti();// Thrued
    SyuIti();
}


2022-09-29 21:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.