How can I change the scale of a 3D Object and the Audio Source's radius in a proportionally way in Unity 5 using C#? -


i'm using array multiply 3d object randomly in space, i'm getting lot of nice objects floating randomly on y, x , z axes. object has audio source sound attached it, means after applying random-array-positioning different objects different audio sources well.

the problem i'm changing scale of objects, it's working super well, size/scale/radius of audio source it's not changing @ all.

how can change scale of objects , change size/scale/radius of audio source @ same time, match both equally or proportionally in size?

i'm looking here can't figured out. https://docs.unity3d.com/scriptreference/audiosource.html

this code i'm using for:

using system.collections; using system.collections.generic; using unityengine;  public class multipleobjectsgrandes : monobehaviour {  public gameobject prefabgrandes;  public gameobject[] gos; public int cantidad; public float minscaleobj; public float maxscaleobj;   void awake() {     gos = new gameobject[cantidad];     for(int = 0; < gos.length; i++)     {          //position         vector3 position = new vector3(random.range(-40.0f, 40.0f), random.range(-40.0f, 40.0f), random.range(-40.0f, 40.0f));         gameobject clone = (gameobject)instantiate(prefabgrandes, position, quaternion.identity);          //scale         clone.transform.localscale = vector3.one * random.range(minscaleobj, maxscaleobj);          //rotation         clone.transform.rotation = quaternion.euler(random.range(0.0f, 360.0f), random.range(0.0f, 360.0f), random.range(0.0f, 360.0f));          gos[i] = clone;     }   } } 

this code i'm using multiply objects:

    using system.collections;     using system.collections.generic;     using unityengine;      public class multipleobjectsgrandes : monobehaviour     {      public gameobject prefabgrandes;      public gameobject[] cuerpos;     public int cantidad;     public float minscaleobj;     public float maxscaleobj;      public float escalamax;      void awake ()     {         cuerpos = new gameobject[cantidad];         (int = 0; < cuerpos.length; i++) {              //position             vector3 position = new vector3 (random.range (-40.0f, 40.0f), random.range (-40.0f, 40.0f), random.range (-40.0f, 40.0f));              gameobject clone = (gameobject)instantiate (prefabgrandes, position, quaternion.identity);              //scale             clone.transform.localscale = vector3.one * random.range (minscaleobj, maxscaleobj);              //rotation             clone.transform.rotation = quaternion.euler (random.range (0.0f, 360.0f), random.range (0.0f, 360.0f), random.range (0.0f, 360.0f));              escalamax = clone.transform.localscale.x;              //debug.log(escalamax);              }         }     } 

everything ok here when i'm debugging "escalamax" in console.

the variable "escalamax" 1 i'm passing other script inside object i'm multiplying has audiosource attached it. script:

using system.collections; using system.collections.generic; using unityengine;  [requirecomponent (typeof(audiosource))]  public class audiorandompitch : monobehaviour {      public float startingpitch = 1;     public float minpitchrandom = 0;     public float maxpitchrandom = 0;     audiosource audio;      public float audioscale;      void start ()     {         startingpitch = random.range (minpitchrandom, maxpitchrandom);         audio = getcomponent<audiosource> ();         audio.pitch = startingpitch;          gameobject themultiplicator = gameobject.find ("multiplicador_decuerpos");         multipleobjectsgrandes multiplicatorscript = themultiplicator.getcomponent<multipleobjectsgrandes> ();         multiplicatorscript.escalamax = audioscale;          //this not working         audio.maxdistance = audioscale;          debug.log(audioscale);        } } 

here i'm first saving value coming other script escalamax inside new variable audioscale. problem when try pass audioscale value audio.maxdistance var.

i'm super close know, can see, i'm not programmer , i'm doing stupidly wrong... :/

thanks help!


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -