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 PISSDRANK8792 · Jul 30, 2013 at 11:21 PM · gameobjectmodelscriptingbasicsmodel importing

Models don't work as a gameObject in my script, i'm confused! Help!

  • have a brain model, i need to make click in each part of this and show a GUI with text, here is the code embed to a "model" who does not but ir works in capsules, cubes etc.* Character- using UnityEngine; using System.Collections;

public class Character : MonoBehaviour { public string myWords = string.Empty;

 private void Start () 
 {    
 
 }
 
 private void Update ()
 {
     
 }
 
 public string GetWords ()    
 {
     return myWords;
 }    

}

now this is the code for the MainCamera who allows you to click a gameobj and showing text from GetWords string and if you click outside of any gameObject this UI closes.

UI_Demo- using UnityEngine; using System.Collections;

 public class UI_Demo : MonoBehaviour
 {
     private GameObject clicked = null;
     
     private void Start()
     {
     
     }
     
     private void Update ()
     {
         if (Input.GetMouseButtonDown(0)) 
         {
             RaycastHit hit;
             
             if (Physics.Raycast(Camera.mainCamera.ScreenPointToRay(Input.mousePosition), out hit))
             {                
                 if (hit.collider.gameObject.GetComponent<Character>() != null)
                     clicked = hit.collider.gameObject;
                 else
                     clicked = null;
             }
             else 
                 clicked = null;
         }
     }
     private void OnGUI()
     {
         if (clicked != null)
             GUI.Label(new Rect(15,15,200,25), clicked.GetComponent<Character>().GetWords());
         }
     }
 

thy thing is that the script works only in gameObj and i'm a n00b ¿how can i make a imported FBX a gameObject? or why i can't make the script work right if i attach it to a imported model? )':

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 tw1st3d · Jul 31, 2013 at 12:27 AM 0
Share

Why don't you define your game object as public and define it in the inspector?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Jul 30, 2013 at 11:23 PM

You likely need a mesh collider added to your model. Select the game object in he hierarchy and then do Component > Physics > Mesh Collider.

Comment
Add comment · Show 3 · 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
avatar image PISSDRANK8792 · Jul 30, 2013 at 11:47 PM 0
Share

it does not work for me :'(

avatar image robertbu · Jul 31, 2013 at 12:02 AM 0
Share

Next is to figure out what is happening with your Raycast. Just above line 18:

 Debug.Log(hit.collider.name+", "+hit.collider.tag);

This will see if you are hitting anything, and if so, if it is what you expect. If it is hitting he game object you expect, then check to see if the GetComponent() call is failing.

If the debug does not print at all, remove the mesh collider and replace it with a sphere collider to debug the situation. If the sphere works but the mesh does not, you may have to make changes to your model.

avatar image PISSDRANK8792 · Jul 31, 2013 at 03:12 AM 0
Share

thy colider helpd!!!!! can you keep helping me in my proyect via chat )':?

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

16 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

Related Questions

Blender meshes become transparent 1 Answer

Is it possible to deform the polygons of the game object (change the position of the polygon relative to other polygons)? 0 Answers

Distructible plants and dirt. 0 Answers

TEACHABLE MACHINE MODEL & UNITY 1 Answer

Create a GameObject 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