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 UchihaKuriso · Nov 20, 2013 at 11:39 AM · arraymouseraycastingclickcustomization

Character Customization Problem, Hard to explain... JS

Hi. So I'm making a character customization system out of boredom, and ran into a few problems. So far the character is a spaceship, or robot or it can be whatever.

It works with each part having points it extends from with more parts. So far I made clicking on a point extend a parts choices tree, and when you click on one of the parts it gets attached and moves to the point. That's all fine.

The problem is even tho its working I'm getting errors once I click on the part I wanna attach. Now I think the problem lays somewhere in my raycasting and assigning some temporary variables, but I can't pinpoint it. Debug isn't helping either.

I have 4 points and when I click on one to make the choice tree appear, Debug runs on all points. And when I click on a part(with part script) I get the error object reference not set to an instance(in point script) but it doesn't exactly tell me what I'm not setting. It just points to "if(hitObject.myName == myName)" in the Point script but I don't get it.

Here's both scripts. I commented on the lines what they're suppose to do if anyone can tell me where I'm making a mistake.

Point

 #pragma strict
 var side : String;
 var myName : String;
 var choiceParent : GameObject;
 var parts : GameObject[];
 var choicePlaces : Transform[];
 var hitObjects : GameObject[];
 var checkingHit : boolean;
 
 function Update()
 {
     if(Input.GetMouseButtonDown(0))
     {
         var hit : RaycastHit;
         var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit))
         {
             var hitObject = hit.collider.gameObject.GetComponent(Point);
             Debug.Log(hit.collider.gameObject.name); //check which object is hit, all have different myName variables
             if(hitObject.myName == myName) //point checking if hit object is me so i do the showing choices stuff
             {
                 checkingHit = true; //just another debug check
                 Instantiate(choiceParent, transform.position, transform.rotation); //make the parts choice tree
                 for(var i = 0; i < choicePlaces.Length; i++)
                 {
                         var availableChoices = Instantiate(parts[i], choicePlaces[i].position, Quaternion.identity); //instantiate all parts available at their positions
                         availableChoices.transform.parent = GameObject.FindWithTag("ChoiceParent").transform; //set their parent to the tree
                         availableChoices.transform.localScale = Vector3(0.1,0.1,0.1); //lower their scale
                         var availableChoicesScript = availableChoices.gameObject.GetComponent(Part); //get script of those parts
                         availableChoicesScript.cameFrom = transform; //tell them where they came from
                 }
             }
         }
     }
 }

Part

 #pragma strict
 
 var myName : String;
 var cameFrom : Transform;
 var done : boolean;
 
 function Update()
 {
     if(Input.GetMouseButtonDown(0))
     {
         var hit : RaycastHit;
         var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit))
         {
             var hitObject = hit.collider.gameObject.GetComponent(Part);
             Debug.Log(hitObject.name);
             if(hitObject.myName == myName) //if part with my name is clicked on
             {
                 var choiceHolder = transform.parent.gameObject; //assign temp parent var
                 transform.parent = null; //get rid of parent
                 Destroy(choiceHolder); //destroy the temp parent var so other choices disappear
                 transform.position = cameFrom.position; //move to the position where it came from
                 transform.parent = cameFrom; //become its child
                 transform.localScale = Vector3(4,4,4); //rescale to normal size
             }
         }
     }
 }

Thank you!

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

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

17 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

Related Questions

Click on GameObject leads to multiple call 1 Answer

Change Camera on (Right) Mouse Click 1 Answer

Problem with OnMouseDown 1 Answer

How do I separate OnMouseDown() from OnMouseDrag() 0 Answers

How to Limit Input.mousePosition or Raycast 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