Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Random Binaries · Dec 31, 2011 at 04:37 PM · javascriptcatapult

What is wrong with this catapult script?

Hi can anyone help me please. I've got two errors with this particular script. The error messages are:

NullReferenceException CatapultMainScript.Start () (at Assets/Scripts For Project/CatapultMainScript.js:24)

NullReferenceException CatapultMainScript.Update () (at Assets/Scripts For Project/CatapultMainScript.js:33)

The script is:

var grenade : GameObject; var throwThis : int = 3200; var rotspeed : int = 10;

private var placeHolder : Transform; private var Launcher : Transform; private var target : GameObject; private var cRight : Transform; private var cLeft : Transform; private var firingForm : float; private var distance : float; private var originalPos : Vector3; private var originalRotation : Quaternion; private var originalThrow : int; private var originalDist : float;

function Start(){

 placeHolder = transform.Find("Catapult Base/Catapult Launcher/Holder");
 target = GameObject.Find("target");
 cRight = target.transform.Find("CubeR");
 cLeft = target.transform.Find("CubeL");
 Launcher = transform.Find("Catapult Base/Catapult Launcher");
 firingForm = Vector3.Distance(placeHolder.transform.position, target.transform.position);
 originalDist = firingForm;
 originalPos = target.transform.position;
 originalRotation = Launcher.transform.rotation;
 originalThrow = throwThis;

}

function Update(){

 placeHolder.transform.LookAt(target.transform);
 if(Input.GetAxis("Mouse X") > 0 && cRight.renderer.isVisible){
     Launcher.transform.Rotate(0, Time.deltaTime * (rotspeed * -1), 0);
     target.transform.Translate(Time.deltaTime * (rotspeed * 2), 0, 0);
     firingForm = Vector3.Distance(placeHolder.transform.position, target.transform.position);
 }

 if(Input.GetAxis("Mouse X") < 0 && cLeft.renderer.isVisible){
     Launcher.transform.Rotate(0, Time.deltaTime * rotspeed, 0);
     target.transform.Translate(Time.deltaTime * (rotspeed * 2) * -1, 0, 0);
 }

 if(Input.GetAxis("Mouse Y") > 0 && target.transform.position.z < 913){
     firingForm = Vector3.Distance(placeHolder.transform.position, target.transform.position);
     target.transform.Translate(0, 0, (Time.deltaTime * (rotspeed * 2)));
 }

 if(Input.GetAxis("Mouse Y") < 0 && target.transform.position.z > 773){
     firingForm = Vector3.Distance(placeHolder.transform.position, target.transform.position);
     target.transform.Translate(0, 0, (Time.deltaTime *(rotspeed * 2) * -1));
 }
 
 if(Input.GetKey("space")){
     Launcher.transform.rotation = originalRotation;
     target.transform.position = originalPos;
     throwThis = originalThrow;
 }
 
 if(Input.GetButtonDown("Fire1")){
     firebomb();
 }

}

function firebomb() {

 animation.CrossFade("fire");
 yield WaitForSeconds(1);
 throwThis = originalThrow - ((originalDist - Vector3.Distance(placeHolder.transform.position, target.transform.position)) *35);
 var clone = Instantiate(grenade, placeHolder.transform.position, placeHolder.transform.rotation);
 clone.rigidbody.AddRelativeForce(Vector3.forward * (throwThis));

} Thank you for your help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Dec 31, 2011 at 07:21 PM

Unity probably can't set one of the variables placeholder, Launcher or target because the respective objects were not found:
1- If there's no object named "target" in the scene, target will not be set;
2- The object that has this script must have a child named "Catapult Base", which must have a child named "Catapult Launcher" to be assigned to the variable Launcher;
3- The child object "Catapult Launcher" must have a child object named "Holder" to be assigned to the variable placeHolder.
Check if these objects exist and if their names are set as above.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Flipping textures 0 Answers

How do I invert the Y axis in Penelope tutorial? 3 Answers

Rotating a Sphere with the mouse? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges