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 MarcioHanPL · Apr 28, 2014 at 07:02 PM · errornullreferenceexception

NullReferenceException: Object reference not set to an instance of an object - error in AdvancedBuildingSystem!

Hello. I download a free Advanced Building System. And, when I start the game, I have error:

Blockquote

NullReferenceException: Object reference not set to an instance of an object AdvancedBuildingScript.Update () (at >Assets/PlayerEngine/BuildingSystem/Scripts/AdvancedBuildingScript.cs:66)

Blockquote

This is script:

 /*
  * Advanced Building System - nDev Studio
  * Version 1.1
  * */
 using UnityEngine;
 using System.Collections;
 
 public class AdvancedBuildingScript : MonoBehaviour {
     //Inspector
     public GameObject Player;
     public bool allowCameraMod = true;
     public GameObject CamHolder, CamTargetPos, CamStartPos;
     public Transform spawnPos;
     public Transform[] BuildingObjects;
     public static int CurrentObj = 1;
     public KeyCode enterBuildMod = KeyCode.Tab, changeCamMod = KeyCode.L, changeRotMod = KeyCode.P, changeMoveMod = KeyCode.O;
     public KeyCode forward = KeyCode.UpArrow, backward = KeyCode.DownArrow, left = KeyCode.LeftArrow, right = KeyCode.RightArrow, up = KeyCode.PageUp, down = KeyCode.PageDown, placeObject = KeyCode.KeypadEnter;
     public Vector3 defaultObjPos;
     public Quaternion defaultObjRot;
     public bool playSounds = true;
     public AudioClip placeSound,errorSound;
     public AudioSource audioSource;
     public bool displayObjName = true;
     public GUISkin GuiSkin;
     //
     bool rotateMod = false;
     bool stepMod = false;
     bool cameraMod = false;
     bool buildMod = false;
 
     void PlaySound(AudioClip clip)
     {
         audioSource.clip = clip;
         audioSource.Play ();
     }
 
     void Start()
     {
         ControlObject (spawnPos, spawnPos, true);
     }
     void Update()
     {
         //Enter/Exit Building Mode
         if (Input.GetKeyDown (enterBuildMod)) {
                         if (buildMod == true) {
                                  ControlObject (spawnPos, spawnPos, true);
                                 buildMod = false;
 
                         } else if (buildMod == false) {
                                 buildMod = true;
                         }
                 }
 
                 
         if (buildMod == true) {
                         RenderObject (BuildingObjects [CurrentObj]);
                         ControlObject (spawnPos,BuildingObjects [CurrentObj],false);
                 } else {
             //Reset Cam
             float cameraspeed = 4.0f;
             float increment = 0.0f;
             if (increment <= 1)
                 increment += cameraspeed / 100;
             
             CamHolder.transform.position = Vector3.Lerp (CamHolder.transform.position, CamStartPos.transform.position, increment);
             Player.GetComponent<MouseLook> ().enabled = true;
             cameraMod = false;
             ResetObjects();
                 }
     }
 
     void ControlObject(Transform obj, Transform objToSpawn, bool reset)
     {
         if (reset == false) {
                         //Move Camera
                         float cameraspeed = 4.0f;
                         float increment = 0.0f;
             if (cameraMod == true && allowCameraMod == true) {
                                 if (increment <= 1)
                                         increment += cameraspeed / 100;
                 
                                 CamHolder.transform.position = Vector3.Lerp (CamHolder.transform.position, CamTargetPos.transform.position, increment);
                                 Player.GetComponent<MouseLook> ().enabled = false; //HERE CHANGE THE nDEVMOUSELOOK WITH YOUR MOUSELOOK SCRIPT NAME
             } else {
                                 if (increment <= 1)
                                         increment += cameraspeed / 100;
                 
                                 CamHolder.transform.position = Vector3.Lerp (CamHolder.transform.position, CamStartPos.transform.position, increment);
                                 Player.GetComponent<MouseLook> ().enabled = true;
                 
                         }
                         //End Move Camera
                         if (Input.GetKeyDown (changeCamMod)) {
                                 if (cameraMod == true)
                                         cameraMod = false;
                                 else
                                         cameraMod = true;
                         }
                         if (Input.GetKeyDown (changeRotMod)) {
                                 if (rotateMod == true)
                                         rotateMod = false;
                                 else
                                         rotateMod = true;
                         }
                         if (Input.GetKeyDown (changeMoveMod)) {
                                 if (stepMod == true)
                                         stepMod = false;
                                 else
                                         stepMod = true;
                 
                         }
                         //Block Movement
                         if (rotateMod == false) {
                                 if (stepMod == false) {
                                         //Smooth Mod
                                         if (Input.GetKey (forward)) {
                                                 obj.Translate (Vector3.forward * (Time.deltaTime + 0.05f));
                                         }
                                         if (Input.GetKey (backward)) {
                                                 obj.Translate (Vector3.back * (Time.deltaTime + 0.05f));
                                         }
                                         if (Input.GetKey (left)) {
                                                 obj.Translate (Vector3.left * (Time.deltaTime + 0.05f));
                                         }
                                         if (Input.GetKey (right)) {
                                                 obj.Translate (Vector3.right * (Time.deltaTime + 0.05f));
                                         }        
                                         if (Input.GetKey (up)) {
                                                 obj.Translate (Vector3.up * (Time.deltaTime + 0.05f));
                                         }
                                         if (Input.GetKey (down)) {
                                                 obj.Translate (Vector3.down * (Time.deltaTime + 0.05f));
                                         }
                                 } else if (stepMod == true) {
                                         //Step Mod
                                         if (Input.GetKeyDown (forward)) {
                                                 obj.Translate (Vector3.forward * BuildingObjects [CurrentObj].localScale.x);
                                         }
                                         if (Input.GetKeyDown (backward)) {
                                                 obj.Translate (Vector3.back * BuildingObjects [CurrentObj].localScale.x);
                                         }
                                         if (Input.GetKeyDown (left)) {
                                                 obj.Translate (Vector3.left * BuildingObjects [CurrentObj].localScale.z);
                                         }
                                         if (Input.GetKeyDown (right)) {
                                                 obj.Translate (Vector3.right * BuildingObjects [CurrentObj].localScale.z);
                                         }        
                                         if (Input.GetKeyDown (up)) {
                                                 obj.Translate (Vector3.up * (BuildingObjects [CurrentObj].localScale.y));
                                         }
                                         if (Input.GetKeyDown (down)) {
                                                 obj.Translate (Vector3.down * (BuildingObjects [CurrentObj].localScale.y));
                                         }
                                 }
                 
                         }
                         //Block Rotation
                         if (rotateMod == true) {
                                 if (Input.GetKey (forward)) {
                                         obj.Rotate (Vector3.left * (Time.deltaTime + 1));
                                 }
                                 if (Input.GetKey (backward)) {
                                         obj.Rotate (Vector3.right * (Time.deltaTime + 1));
                                 }
                                 if (Input.GetKey (left)) {
                                         obj.Rotate (Vector3.up * (Time.deltaTime + 1));
                                 }
                                 if (Input.GetKey (right)) {
                                         obj.Rotate (Vector3.down * (Time.deltaTime + 1));
                                 }        
                         }
             
                         //Place Object
                         if (Input.GetKeyDown (placeObject)) {
                                 if (BuildingObjects [CurrentObj].GetComponent<BuildingObj> ().ObjectAmount > 0) {
                                         BuildingObjects[CurrentObj].GetComponent<BuildingObj>().enablePreview = false;
                                         Instantiate (BuildingObjects [CurrentObj].gameObject, obj.position, obj.rotation);
                                         BuildingObjects [CurrentObj].GetComponent<BuildingObj> ().ObjectAmount -= 1;
 
                     if (playSounds == true)
                     {
                         PlaySound (placeSound);
                     }
                                 } else {
                                         Debug.Log ("Not enough Objects");
                                         CurrentObj = 0;
                     if (playSounds == true)
                     {
                         PlaySound (errorSound);
                     }
                                 }
                         }
 
                 } else if (reset == true) {
                         obj.localPosition = defaultObjPos;
                         obj.localRotation = defaultObjRot;
                 }
     }
 
     void RenderObject (Transform obj)
     {
         if (CurrentObj == 0)
         {
            cameraMod = false;
            ResetObjects ();
         } 
         else 
         {
             if (BuildingObjects[CurrentObj].GetComponent<BuildingObj>().ObjectAmount > 0)
             {
                 BuildingObjects[CurrentObj].active = true;
                 BuildingObjects[CurrentObj].GetComponent<BuildingObj>().enablePreview = true;
             }
             else
             {
                 CurrentObj = 0;
                 Debug.Log ("Not Enough Objects");
             }
         }
     }
 
     public void ResetObjects()
     {
         foreach (Transform obj in BuildingObjects) 
         {
             obj.active = false;
         }
     }
 
     public void AddObjectAmount(int objIndex,int addAmount)
     {
         BuildingObjects [objIndex].GetComponent<BuildingObj> ().ObjectAmount += addAmount;
     }
 
     void OnGUI()
     {
         GUI.skin = GuiSkin;
         if (displayObjName == true && buildMod == true) 
         {
             string currentObjName = BuildingObjects[CurrentObj].GetComponent<BuildingObj>().ObjectName;
             GUI.Label (new Rect(20,20,250,30),currentObjName);
         }
     }
 }


So? Anyone can help me?? Please :) I download this package from: http://armedunity.com/topic/7280-advanced-building-system-ndev-studios/page-2

Comment
Add comment · Show 1
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
avatar image OrbitSoft · Apr 28, 2014 at 08:00 PM 0
Share

On line 66 the script is accessing the Player gameObject and the mouse look script, check if the Player GameObject is set in the inspector and if it has a $$anonymous$$ouseLook script

0 Replies

· Add your reply
  • Sort: 

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NullReferenceExeption: Object reference not set to an instance of an object. 1 Answer

What is wrong with my script? 1 Answer

NullReferenceException: Object reference not set to an instance of an object. 2 Answers

NullReferenceException - Why? 2 Answers

Unity 3.4.0 Running really slow 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