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 oliver-jones · Nov 26, 2010 at 01:38 AM · texturecollidermouseglobalclickable

Click On Objects Within Scene

Hello,

I have no idea how to select objects within my scene that have a collider. I basically want a 2 scripts, one with the clickable command on, and another that makes a variable true if the click is true.

Here is what I have (Big Problem):

I have 3 cubes on my scene, all with the click script and the variable script (within different children). Now when I click on any of the cubes, the variable it true for all the cubes, I only want it true for that cube I just clicked on

(When clicked on cube, a texture is placed around it) - now if I click on one cube, the texture comes on for all the cube. Or sometimes different cubes activate the textures on another cube???

Heres my script:

ClickObject::

#pragma strict

var clicked : boolean = false; var hit : RaycastHit;

static var ClickedOn : boolean = false;

function Update() { if(Input.GetMouseButtonDown(0) && collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, Mathf.Infinity)) { clicked = !clicked; if(tag == "Select") tag = "Unselect"; else tag = "Select"; //Debug.Log("clicked" + (clicked? "" : " off")); }

ClickedOn = clicked;

}

RadiusTexture:

var RadiusObject : Transform; var RadiusSphere : Transform; private var CurrentSize : float;

private var ScaleX = 3.1; //2 private var ScaleY = 0; //0 private var ScaleZ = 3.4; //2.3

private var ScaleXDiv : float = 0; private var ScaleYDiv : float = 0; private var ScaleZDiv : float = 0;

private var ScaleXNew : float = 0; private var ScaleZNew : float = 0;

private var Clicked = false; var MouseOverClicked = false;

var Texture = true;

function Update () {

 if(ClickObject.ClickedOn == true)
 {
     if(Texture == true)
     {
         CurrentSize = collider.radius;

         ScaleXDiv = (ScaleX * CurrentSize);
         ScaleXNew = ScaleXDiv / 10;

         ScaleZDiv = (ScaleZ * CurrentSize);
         ScaleZNew = ScaleZDiv / 10;

         RadiusObject.transform.localScale = Vector3(ScaleXNew,ScaleY,ScaleZNew);
     }
     else
     {
         CurrentSize = collider.radius;
         RadiusSphere.transform.localScale = Vector3(CurrentSize * 3,CurrentSize * 3,CurrentSize * 3);

     }
     //Clicked = true;
 }
 else if(ClickObject.ClickedOn == false)
 {

     RadiusObject.transform.localScale = Vector3(0,0,0);
     RadiusSphere.transform.localScale = Vector3(0,0,0);

     //Clicked = false;

 }

}

What I want is for the cube clicked - to activate the texture, and not interfere with the other cubes/textures

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

2 Replies

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

Answer by BerggreenDK · Nov 26, 2010 at 04:20 AM

I think you should have a look at this question first. Looks very similar:

http://answers.unity3d.com/questions/28481/clickable-object-problem-help

I believe its all about making the object you can click have the script itself, thats the "object oriented way of doing stuff". You attach the triggerscript to "clickable stuff" instead of a screen/mouse object that scans from point of view.

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 oliver-jones · Nov 26, 2010 at 11:31 AM 0
Share

I've taken a look at that post (which is my older post btw). But its still not answering my question. I need to make the click unique to whatever object I click on. I believe its something to do with the if(ClickObject.ClickedOn == true) in the RadiusScript, how would I make that a unique variable?

avatar image BerggreenDK · Nov 27, 2010 at 03:17 AM 0
Share

let me get this right, you have "some objects" and when one is clicked you need to know exactly which one?

avatar image nazia · Jan 05, 2011 at 01:18 PM 0
Share

this is my problem too.Please help:(

avatar image
0

Answer by chris 4.du · Nov 27, 2010 at 10:27 AM

did you duplicate the other two cubes from the original cube? If so, that may the problem.

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 oliver-jones · Nov 27, 2010 at 12:41 PM 0
Share

Yes, I did - why would that be a problem? Thanks

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

No one has followed this question yet.

Related Questions

How can I capture a mouse position on an invisible plane without a collider? 2 Answers

How can I only instantiate if mouse over? 1 Answer

Find out if mouseposition is over gui-element or collider? 2 Answers

OnMouseUp not always firing on mesh that is changing 0 Answers

Touch command for GUIText on Android? OnMouseDown() for Android? 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