renderer.material.shader = shader2; //Help me How can i change 1 value ?

please guide me here -
// line 30 why my shader is not changing ??

using UnityEngine;
using System.Collections;
 
public class powerup2 : MonoBehaviour {
       
       
        public static bool powerup2ON;
        public int powerup2_status;
       
       
    public Shader shader1 = Shader.Find("MADFINGER/Diffuse/Simple");
        public Shader shader2 = Shader.Find("MADFINGER/Transparent/Blinking GodRays");
       
        // Use this for initialization
        void Start () {
        transform.Rotate(90, 180, 0);
        powerups.Load_powerup_2_status();
        }
       
        // Update is called once per frame
        void Update () {
       
        }
       
       
        void NoObstacles(){
                GameObject[] obstacleGameObject = GameObject.FindGameObjectsWithTag("obstacle");
                foreach(GameObject go in obstacleGameObject){
                        go.collider.enabled = false;
                         go.renderer.material.shader = shader2;
                        //go.collider.isTrigger = false;
                       
               
                }
        }
       
        void YesObstacles(){
                GameObject[] obstacleGameObject = GameObject.FindGameObjectsWithTag("obstacle");
                foreach(GameObject go in obstacleGameObject){
                        go.collider.enabled = true;
                         go.renderer.material.shader = shader1;
                        //go.collider.isTrigger = true;
                }
        }
       
       
                        IEnumerator Tcounter5sec_p2(){
                Debug.Log("inside powerup2");
                NoObstacles();
yield return new WaitForSeconds(15.0f);
Debug.Log("15 secs p2 trial");
                Destroy(gameObject);
                YesObstacles();
powerup2ON=false;              
}
       
        IEnumerator Tcounter10sec_p2 (){
                Debug.Log("inside 10sec ");
yield return new WaitForSeconds(10.0f);
Debug.Log("10 secs");
                Destroy(gameObject);
powerup2ON=false;              
}
       
        void OnTriggerEnter(Collider other) {
                if(other.gameObject.tag == "Player"){
                        powerup2ON=true;
                        Debug.Log("I am Power up 2");
                        powerup2_status = powerups.p2stat;
                        Debug.Log(powerup2_status);
                        if(powerup2_status==0){
                                Debug.Log("I am Power up 2-inside if");
                                StartCoroutine (Tcounter5sec_p2());
                        }
                       
                        else if(powerup2_status==1  powerup2ON==true){
                                StartCoroutine(Tcounter10sec_p2());
                        }
                        //Destroy(gameObject);
    }}
       
         void OnBecameInvisible() {
                //StartCoroutine(Tcounter5sec());
               
               
                //Debug.Log("Invisible Obstacle");
        //Destroy(gameObject);
    }
       
}

and how can i change the value of “Near fadeout dist” of this shader to 100 from the script ?? >>


You can’t change values in shaders. You have to change the values in the material.

In your case you probably need that one:

Can you please add the exact needed code above, am kind of confused

That’s the part which is relevant for you:

renderer.material.SetFloat("_Shininess", shininess);

Of course your property is not named _Shininess, but you can have a look at your shader and check what the actual name is. And you said you want the value be 100, so replace shininess with 100.

in my shader code for the property is like

_FadeOutDistNear ("Near fadeout dist", float) = 10

which means my code should be -

go.renderer.material.SetFloat("_FadeOutDistNear", 100);

but where have i declared the shader ??

like - go.renderer.material.shader = shader2;

and should i use “go” in front, i think i should, so what will be final line accordingly ?

This is the code where i need to fit -

public Shader shader1 = Shader.Find("MADFINGER/Diffuse/Simple");
	public Shader shader2 = Shader.Find("MADFINGER/Transparent/Blinking GodRays");

	void NoObstacles(){
		GameObject[] obstacleGameObject = GameObject.FindGameObjectsWithTag("obstacle");
		foreach(GameObject go in obstacleGameObject){
			go.collider.enabled = false;
			 go.renderer.material.shader = shader2;
			//go.collider.isTrigger = false;
			
		
		}
	}
	
	void YesObstacles(){
		GameObject[] obstacleGameObject = GameObject.FindGameObjectsWithTag("obstacle");
		foreach(GameObject go in obstacleGameObject){
			go.collider.enabled = true;
			 go.renderer.material.shader = shader1;
			//go.collider.isTrigger = true;
		}
	}
go.renderer.material.SetFloat("_FadeOutDistNear", 100);

That is correct. Usually your renderers have already the correct material with the correct shader, meaning you don’t have to set another shader. On the other hand if you need to switch the shader, you need to assign the shader to the material before you can change values.

go.renderer.material.shader = shader2;
go.renderer.material.SetFloat("_FadeOutDistNear", 100);

I added these lines, but still not effecting, may latest code here -

Line no. 32,33
What can be the reason ??

using UnityEngine;
using System.Collections;

public class powerup2 : MonoBehaviour {
	
	
	public static bool powerup2ON;
	public int powerup2_status;
	
	
    public Shader shader1 = Shader.Find("MADFINGER/Diffuse/Simple");
	public Shader shader2 = Shader.Find("MADFINGER/Transparent/Blinking GodRays");
	
	// Use this for initialization
	void Start () {
	transform.Rotate(90, 180, 0);
	powerups.Load_powerup_2_status();
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	
	void NoObstacles(){
		GameObject[] obstacleGameObject = GameObject.FindGameObjectsWithTag("obstacle");
		foreach(GameObject go in obstacleGameObject){
			
			go.collider.enabled = false;
			Debug.Log("box collider disabled");
			go.renderer.material.shader = shader2;
            go.renderer.material.SetFloat("_FadeOutDistNear", 100);
			//go.collider.isTrigger = false;
			
		
		}
	}
	
	void YesObstacles(){
		GameObject[] obstacleGameObject = GameObject.FindGameObjectsWithTag("obstacle");
		foreach(GameObject go in obstacleGameObject){
			go.collider.enabled = true;
			 go.renderer.material.shader = shader1;
			//go.collider.isTrigger = true;
		}
	}
	
	
			IEnumerator Tcounter5sec_p2(){
		Debug.Log("inside powerup2");
		NoObstacles();
yield return new WaitForSeconds(15.0f);
Debug.Log("15 secs p2 trial");
		Destroy(gameObject);
		YesObstacles();
powerup2ON=false;		
}
	
	IEnumerator Tcounter10sec_p2 (){
		Debug.Log("inside 10sec ");
yield return new WaitForSeconds(10.0f);
Debug.Log("10 secs");
		Destroy(gameObject);
powerup2ON=false;		
}
	
	void OnTriggerEnter(Collider other) {
		if(other.gameObject.tag == "Player"){
			powerup2ON=true;
			Debug.Log("I am Power up 2");
			powerup2_status = powerups.p2stat;
			Debug.Log(powerup2_status);
			if(powerup2_status==0){ 
				Debug.Log("I am Power up 2-inside if");
				StartCoroutine (Tcounter5sec_p2());
			}
			
			else if(powerup2_status==1  powerup2ON==true){
				StartCoroutine(Tcounter10sec_p2());
			}
			//Destroy(gameObject);
    }}
	
	 void OnBecameInvisible() {
		//StartCoroutine(Tcounter5sec());
		
		
		//Debug.Log("Invisible Obstacle");
        //Destroy(gameObject);
    }
	
}

Try getting rid of the “Find” and assign the shader manually in the inspector and see if that changes anything?

Are YesObstacles and NoObstacles called at the time you expect it?