x


Android Build help needed regarding ball throw

I am using this script which is running perfectly alright and the ball is thrown forward properly.

var ballPrefab : Transform; function OnGUI() { var e : Event = Event.current; if(e.button == 0 && e.isMouse){ //Debug.Log("Left Click"); if(actionStatus == false) { if(slabstatus1.Balls_count<3){ if(Input.GetButtonDown("Fire1")) { var ball = Instantiate(ballPrefab, transform.position, Quaternion.identity); ball.rigidbody.AddForce(transform.forward * 900); } actionStatus = true; } } } }

I changed platform to Android to build and run. The scrip shows compiler error:

BCE0019: 'rigidbody' is not a member of 'UnityEngine.Object' Error building because scripts had compiler errors UnityEditor.HostView:OnGUI() Exception: Error building Player because scripts had compiler errors UnityEditor.BuildPlayerWindow.BuildPlayerWithDefaultSettings (Boolean askForBuildLocation, BuildOptions forceOptions) (at C:...)

I changed the script to:

var ballPrefab : GameObject; and
if(Input.GetButtonDown("Fire1")) { var ball: GameObject = Instantiate(ballPrefab, transform.position, Quaternion.identity) as GameObject; ball.rigidbody.AddForce(transform.forward * 900);

Now, there is another compiler error: NullReferenceException: Object reference not set to an instance of an object

and 'rigidbody' error is cleared.

Kindly help me resolve this error.

Regards,

Zia Khatri

more ▼

asked Jul 13, 2011 at 04:52 PM

ziakhatri gravatar image

ziakhatri
1 7 6 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Just had to remove the script from the ball prefab in camera and re-set.

It worked well.

more ▼

answered Jul 14, 2011 at 04:31 PM

ziakhatri gravatar image

ziakhatri
1 7 6 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4852
x3165
x2115
x285
x57

asked: Jul 13, 2011 at 04:52 PM

Seen: 1718 times

Last Updated: Jul 14, 2011 at 04:31 PM