Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Add variable from another script?

$
0
0
I created these two scripts: 1) public var goTransform:Transform; var sp:float = 0.5f; var Incrementscript : Increment; function Awake() { goTransform = this.GetComponent(Transform); } function Update() { goTransform.position.z = goTransform.position.z - sp; } function OnTriggerEnter(other : Collider) { if (GetComponent.().tag == "Inc") { sp = sp + Incrementscript.incr; } } 2) #pragma strict var incrementTime = .1; var incrementBy = 0.05; static var incr = 0.5; function Awake () { InvokeRepeating("Incrementvar", incrementTime, incrementTime); } function Incrementvar () { incr += incrementBy; } every x seconds is spawned a prefab that contains the first script. The second script is contained in a gameobject trigger. the sp variable contained in the prefab(script 1), passing through the trigger, should add up to the incremented number in this second script, increasing the speed (sp) of the prefab. in this way each prefab will have a different speed, more and more high. The number increases but is added to sp, what I did wrong?

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>