Can someone translate the following piece of code into Javascript please?
I realise that parts of it is already in Javascript. The only lines that my version of the Unity3D has problems with are the following:
particles_.position = Vector3.Lerp(particles*.position; transform.position; Time.deltaTime / 2.0f); //On Line 14*_
& for (var i:int = 0; i < particles.GetUpperBound(0)){ //On Line 12 Here’s all of the script together:
var p:ParticleEmitter; var particles:Particle[]; function Start() { p = (ParticleEmitter)(GameObject.Find(“Magical Fire Smoke”).GetComponent(typeof(ParticleEmitter))); particles = p.particles; } function Update() { for (var i:int = 0; i < particles.GetUpperBound(0)) { particles_.position = Vector3.Lerp(particles*.position; transform.position; Time.deltaTime / 2.0f); } p.particles = particles; }
I’ve changed what you recommended and it is still coming up with two errors. Here’s the updated script:
var p:ParticleEmitter;
var particles:Particle;
function Start() {
p = (ParticleEmitter)(GameObject.Find("Magical Fire Smoke").GetComponent(typeof(ParticleEmitter)));
particles = p.particles;
}
function Update() {
var i = 0;
for (i = 0; i < particles.GetUpperBound(0))
{
particles_.position = Vector3.Lerp(particles*.position; transform.position; Time.deltaTime / 2.0f);*_
} p.particles = particles; } The lines that it is highlighting are: for (i = 0; i < particles.GetUpperBound(0)) //Line 12 The error message for this is: BCE0044: expecting ;, found ‘)’ The lines that it is highlighting are: particles_.position = Vector3.Lerp(particles*.position; transform.position; Time.deltaTime / 2.0f);//Line 14* The error message for this is: BCE0044: expecting :, found ‘=’._
Ok, here's the whole script from the 2nd link you posted up there, converted to javascript.
#pragma strict
public var p : ParticleEmitter ;
public var particles : Particle[] ;
public var affectDistance : float ;
var sqrDist : float ;
var thisTransform : Transform ;
function Start(){
thisTransform = transform ;
p = GameObject.Find("StrangeParticles").GetComponent(ParticleEmitter) ;
particles = p.particles ;
sqrDist = affectDistance * affectDistance ;
}
function Update(){
var dist : float ;
for(var i=0 ; i < particles.GetUpperBound(0) ; i++){
dist = Vector3.SqrMagnitude(thisTransform.position - particles*.position) ;*
*if(dist < sqrDist){*
<em>particles_.position = Vector3.Lerp(particles*.position, thisTransform.position, Time.deltaTime / 2) ;*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*p.particles = particles ;*_</em>
<em>_*}*_</em>
<em>_*```*_</em>
<em>_*<p>I'm new to C# also, haven't even bothered reading any of it until the passed week of being on this site, hopefully the conversion is right and it works for you.</p>*_</em>