I wrote this in Unity for PC and it worked fine. But now that I’m working with Unity iPhone I get this error.
This is the code is was mad about
var bomb: Rigidbody ;
private var timer = 0.0;
var Interval = 3;
var Vel = 1;
var Shot : AudioClip;
function Update () {
timer += Time.deltaTime;
if (timer > Interval) {
timer = 0.0;
clone = Instantiate(bomb, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3(0,-1,0) * Vel);
audio.clip = Shot;
audio.Play();
}
}
you need to cast it correctly or access the right component, Unityscripts automagic only exists on Unity 2.x on the desktop
velocity would be a field of a rigidbody, so get the rigidbody of it or check whats going wrong
you need to cast it correctly or access the right component, Unityscripts automagic only exists on Unity 2.x on the desktop
velocity would be a field of a rigidbody, so get the rigidbody of it or check whats going wrong
how would you cast it for Unity iPhone?
you were right. Velocity is what’s messing with this. If I remmed this out the code got no errors. Any idea how i can still use velocity?
get the game objects (cast it to be a game object, otherwise its only UnityEngine.Object and will not work with you at all) rigidbody and access the velocity on it
var clone : GameObject = Instantiate(bomb, transform.position, transform.rotation);
var clonesRb : Rigidbody = clone.GetComponent(Rigidbody);
if(clonesRb) { clonesRb.velocity = ... ; }
[EDIT: thx dreamora for correction]
that makes no sense at all as what you instantiate is either a gameobject or a prefab normally not a rigidbody or a single component at all