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 Jaden14541 · Jun 27, 2014 at 03:58 AM · c#rotation

Rotation scripts logging error messages?

Ok, so I've been working on a little space game and I have a couple buggy scripts. My ship is flying around and rotating fine. It's model along with some thruster particles, lights and such are all attached to an empty GameObject. The ship rotates around fine, but the thrusters didn't want to cooperate with the controller script so I made a couple other ones to sync the ship's rotation with theirs. Here's the script attached to the ship model(and yes, I know my code is sloppy. I'm working on it x3):

 using UnityEngine;
 using System.Collections;
 
 public class StartershipRotation : MonoBehaviour {
 
 
     public float rotationX;
     public float rotationY;
     public float rotationZed;
 
 
     void Start() 
     {
         rotationX = 0;
         rotationY = 0;
         rotationZed = 0;
     }
 
 
     void Update() 
     {
         rotationX = gameObject.transform.rotation.eulerAngles.x;
         rotationY = gameObject.transform.rotation.eulerAngles.y;
         rotationZed = gameObject.transform.rotation.eulerAngles.z;
     }
 
 
 
 }


That script should log the ship's rotation values to some variables. This next script attached to the thrusters reads it:

 using UnityEngine;
 using System.Collections;
 
 public class AutoRotate : MonoBehaviour {
 
     
     public float selfX;
     public float selfY;
     public float selfZ;
 
 
     void Start()
     {
         transform.Find("Startership");
     }
 
 
     void Update() 
     {
         //Update Variables
         selfX = transform.Find("Startership").GetComponent<StartershipRotation>().rotationX;
         selfY = transform.Find("Startership").GetComponent<StartershipRotation>().rotationY;
         selfZ = transform.Find("Startership").GetComponent<StartershipRotation>().rotationZed;
 
         //Change Self Rotation Values
         transform.Rotate(selfX, selfY, selfZ * Time.deltaTime);
     }
 
 
 }
 

The error I get is: "NullReferenceException: Object reference not set to an instance of an object AutoRotate.Update () (at Assets/Scripts/AutoRotate.cs:21)"

Any help would be greatly appreciated.

Thanks in advance, Jaden14541

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 gjf · Jun 27, 2014 at 10:11 AM

that error is likely caused by one or both of the following:

1) there's no object named 'Startership'.

2) there's no StartershipRotation script attached to the 'Startership' object.

Start() in StartershipRotation is unnecessary.

also, what is the point of transform.Find("Startership"); in Start() of AutoRotate?

that function returns the Transform component of a child that you're not doing anything with.

you could probably achieve the desired results in a simpler way (but without seeing all of the code, it's hard to advise).

the best advice is to find a way to get the thrusters working with the controller. post that script, and ask for help fixing it...

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Flip over an object (smooth transition) 3 Answers

GetComponent().enabled = true; 1 Answer

Object reference not set to an instance of an object (Raycast) 1 Answer

Shooting problem the bullets fly in diffrent direction then player looks? 2 Answers


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