Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 oppyJ · Sep 14, 2018 at 07:50 AM · raycastfbxraycastingeventsystemclickable

Making own character clickable

Greetings all,
I have a scene. What I am trying to do is create a 2D looking game which actually uses 3D assets but how its viewed by camera makes it seem 2D.
I have my own characters .fbx. I want to be able to insert them into the scene and click on them. When I click on them I will move the character and change the character animation too. On the character (fbx) I add a collider and rigid body.
The problem I am having is b4 I can even get to the animation & change position stuff, being able to click on the character is problematic.
i.e. I drag the character into the scene. I also create a generic cube asset via Unity. I have a text to update "you have clicked " just for visual rep of what has been clicked.
I have looked online about IPointerClick interface (implement this interface to receive OnPointerClick callbacks. I have an Event System in the Scene to allow click detection. PhysicsRaycaster is attached to the Camera) .
Also looked into tried the GetMouseButtonDown() method.
I have a script attached to the camera:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class youTubeObjectClicker : MonoBehaviour {

 public Text youClickedHint;

 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {
     //only if the button is down or screen clicked
     if (Input.GetMouseButtonDown(0)) { 

     RaycastHit hit;
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

         if (Physics.Raycast(ray, out hit, 100.0f))
         {
             if (hit.transform != null)
             {
                 PrintName(hit.transform.gameObject);
                 print(Input.mousePosition);

                 Rigidbody rigBod;
                 //if it has a RB 
                 if (rigBod = hit.transform.GetComponent<Rigidbody>()) {
                
                     print(Input.mousePosition);

                 }
             }
         }
     } //end if clicked
 } //end update


 private void PrintName(GameObject go) {
     print(go);
     youClickedHint.text = go.name + " is clicked by mouse";
 }


}


I have added the character to their own layer. The Physics Raycaster --> under Event Mask has this layer of characters included.
In the scene I have a cube, 3 animals of the same type using the same fbx and a character of a boy. The cube is the unity made 3D Object --> Cube. The others are .fbx's.
Press Play and you can click each character and the cube. The cube you can click anywhere on the cube. The fbx characters tho (with rigid body and collider added after import to Unity) I have to click a certain small point on the character for it to register the click.
So I wonder 1) What controls the selection area (via click , mouse pointer in Unity but will be finger touch on mobile) and 2) what is the best way to capture the click on each fbx character?
I would like to be able to click anywhere on the character. The area of the collider covers all the clickable area I want for the characters.

I am new to working with fbx's. Other work ive done with Unity so far uses Unity in-editor made assets.
Thanks

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 tormentoarmagedoom · Sep 14, 2018 at 08:25 AM

Good day.

I think the best way is using OnMouseDown() function. But you need to read the manual of the method, This method needs that the object you click have a Collider and (i dnt remeber) also a Rigidbody.

Check the manual.

Keep in mind that you have different methods of this style: OnMOuseOver, OnMouseDown, OnMouseUp

Good luck! Bye!

Comment
Add comment · Show 1 · 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 oppyJ · Sep 17, 2018 at 07:11 AM 0
Share

Thanks @ tormentoarmagedoom for taking time to reply.

Yep I read the docs, have a collider and rigid body as mentioned :) I just wondered if it was say the collider that 'registered the click' (this its this size that 100% holds the boundaries for the clickable area of the character its applied to). Or whether this is done by another component of this asset, its not clear from the docs.

With a little experience in Unity, I wondered what others have prefered to use for this job (method wise/ Unity API wise in general). I hear you say that On$$anonymous$$ouseDown() route u think is best, awesome! I shall persist with this one our of the two.

Cheers

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

133 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem With Raycasthit Angle 0 Answers

Diagonal Raycasting to detect platform returns true, even when false 1 Answer

camera.ScreenPointToRay always has same origin... 1 Answer

Why doesn't Physics.Raycast(ray, RaycastHit, distance) work? 1 Answer

Help Playing "Sound Clip" on RayCastHit? (RayCast help?) 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