- Home /
shooting script error (java)
So i got this error:
MissingMethodException: Method not found: 'UnityEngine.Rigidbody.Addforce'.
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target,
System.Type targetType, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target,
System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices+c_AnonStorey13.<>m_7 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get
(Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key,
Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String
cacheKeyName, System.Type[] cacheKeyTypes, System.Object[] args,
Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String
cacheKeyName, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory
factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name,
System.Object[] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name,
System.Object[] args, System.Type scriptBaseType)
Move Around.Update () (at Assets/Move Around.js:19)
on this script:
var speed = 8.0; var rotateSpeed = 3.0; var bullitPrefab: Transform;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if (Input. GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,
GameObject.Find("Fire Spawn").transform.position,
Quaternion.identity);
bullit.rigidbody.Addforce(transform.forward * 2000);
}
}
@script RequireComponent(CharacterController)
i don't know java, im just following a tutorial. heres the link to it if you need it: clicky
Answer by Borgo · Feb 01, 2011 at 01:24 PM
Hi!!
its not Java, its Javascript (its very diferent).
Try to cut out the "rigidbody" in this line:
bullit.rigidbody.Addforce(transform.forward * 2000);
In the docs:
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * 10);
In the doc, the instantiate return the Rigidbody, so, I guess it's not necessary to wite ".rigidbody"
I can't test now, so, try this.
Answer by Mike 3 · Feb 01, 2011 at 01:18 PM
AddForce, not Addforce
One small tip though, change:
var bullit = Instantiate(bullitPrefab ...
to
var bullit : Transform = Instantiate(bullitPrefab ...
and you will get compiler errors from the line below it, showing you why it's not working at runtime
yay thank you so much! i really should learn java for unity. but i also want to learn python.