Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MadMapp · Aug 16, 2013 at 07:02 PM · shaderscolormaterials

changing emissive color on particle material

hi guys, im stuck, like the question says, im trying to change the emission color on a particles material, based on distance, i get no errors, the inspector show the distance fine, but the color dosent change, heres the code

 #pragma strict
 
 var distance: float;
 var myTrans:GameObject;
 var targetTrans:GameObject;
 var targets : GameObject[] ;//hold an array of target objects
 
 
 
 function Start()
 {//find all the game objects tagged as target
      targets = GameObject.FindGameObjectsWithTag("shoot me"); 
     //if no target set run function find target
     if(targetTrans==null){
     findTarget();
 }
 }
 
 function findTarget(){
 //randomly pick a target from the collected array
     var newTarget : int = Random.Range( 0, targets.length );
   //set the chosen randomly picked target as the curren target
   targetTrans = targets[newTarget];
   }
   
 function FixedUpdate () {
  distance = Vector3.Distance (myTrans.transform.position, targetTrans.transform.position);
         if (distance >=250){
         myTrans.particleSystem.renderer.material.SetColor ("_Emissive",Color.green);
         }
         if (distance <=249 && distance >=100){
         myTrans.particleSystem.renderer.material.SetColor ("_Emissive",Color.yellow);
         }
         if (distance <=99){
         myTrans.particleSystem.renderer.material.SetColor ("_Emissive",Color.red);
         }
 }
Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Aug 16, 2013 at 07:58 PM 0
Share

Are you sure the shader you are using in the material has an 'Emissive' color? None of the particle shaders do.

avatar image MadMapp · Aug 16, 2013 at 09:03 PM 0
Share

ok i didnt look at the script in the shader, untill now, im using the standard mobile.particle vertexlitblended shader,

i looked in the source and the property i want to effect would be this

 _EmisColor ("Emissive Color", Color) = (.2,.2,.2,0)

so i changed my if statements to myTrans.particleSystem.renderer.material.SetColor ("_EmisColor",Color.red);

but still nothing

avatar image robertbu · Aug 16, 2013 at 10:44 PM 0
Share

I just tried it with the vertexlitblended shader, and it worked fine for me:

 pragma strict
 
 var mat : $$anonymous$$aterial;
 private var pr : ParticleSystemRenderer;
 function Start() {
     pr = particleSystem.renderer;
     pr.material = mat;
     pr.material.SetColor ("_EmisColor",Color.red);
 }
 
 function Update() {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A))
         pr.material.SetColor ("_EmisColor",Color.green);
 }
avatar image MadMapp · Aug 16, 2013 at 11:33 PM 1
Share

ok so i set my emmisive to be white, i changed my start function and added your variables var distance: float; var myTrans:GameObject; var targetTrans:GameObject; var targets : GameObject[] ;//hold an array of target objects var mat : $$anonymous$$aterial; private var pr : ParticleSystemRenderer;

 function Start() {
     
 //find all the game objects tagged as target
      targets = GameObject.FindGameObjectsWithTag("shoot me"); 
     //if no target set run function find target
     if(targetTrans==null){
     findTarget();
 }
  pr = particleSystem.renderer;
     pr.material = mat;
     pr.material.SetColor ("_EmisColor",Color.red);
 }

this should turn the emissive color on the assigned texture to red, but dosent and i get this error now

InvalidCastException: Cannot cast from source type to destination type. targetColor.Start () (at Assets/targetColor.js:19)

the line 19 would refer to the line of code pr = particleSystem.renderer; i also tried changing my if statements to match your code but had a lot of errors which slowed everything, i tried swapping the code to change the texture and not the color but same problem

avatar image MadMapp · Aug 16, 2013 at 11:38 PM 0
Share

perhaps its my objects not the code, perhaps im setting up wrong? let me explain my scene i have many space ships spawning, each space ship object has a particle component, which is a texture of a white target, as the space ship gets closer the target particle material needs to change color

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

One fraction of game object one material, other fraction different material? 1 Answer

a 'bar' or neon like light. 3 Answers

Basic gradient vert shader weirdness with 2+ objects 1 Answer

On Android, Standard Shader metallic/reflective surfaces appear blown out when distant. Look fine in Windows. 2 Answers

Pressing play Causes Re-instancing of material (Editor) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges