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 SuperMasterBlasterLaser · Nov 28, 2014 at 10:22 AM · uicanvasimageworldplace

How to place Image in World Space canvas by mouseclick position?

Hello.

I want to create strategy game. When player clicks place in plane, I want to image appear at this place.

I have created canvas with world space and attached camera to its attributes. Then I have rotated and placed it so my plane and canvas are in same position.

Question: How to make some image appear in place of canvas where I click with my mouse?

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
0
Best Answer

Answer by SuperMasterBlasterLaser · Jan 03, 2015 at 10:41 AM

I have found solution:

         RectTransform rectTransform = pointer.GetComponent<RectTransform>();
         rectTransform.position = position;

Since my Canvas is World Space, I just needed to set position depending on raycast hit.

Comment
Add comment · 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
0

Answer by Kiwasi · Nov 29, 2014 at 07:08 AM

Your in luck. I just recorded a tutorial on a very similar concept. In essense you want to create your image as a prefab then Instantiate it at the mouse position.

https://m.youtube.com/watch?v=Av8fL2PO2KQ

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 SuperMasterBlasterLaser · Nov 29, 2014 at 01:11 PM 0
Share

But you instanciate whole canvas. I have one canvas on my plane and I want to create image on it.

avatar image Kiwasi · Nov 29, 2014 at 08:02 PM 0
Share

Same principle applies.

  • $$anonymous$$ake your image a prefab.

  • Listen for clicks on your plane or canvas.

  • Instantiate the prefab at the click position.

  • Set the parent to the canvas.

Have a go at scripting that. If you have trouble post your script here and I can look over it.

avatar image SuperMasterBlasterLaser · Dec 01, 2014 at 11:17 AM 0
Share

$$anonymous$$y code that will instanciate pointer image:

  public void drawPlacePoint(Vector3 position)
     {
         Vector3 pointPosition = new Vector3(position.x, canvas.transform.position.y, position.z);
         GameObject pointer = Instantiate(movePlacePointerPrototype, pointPosition, movePlacePointerPrototype.transform.rotation) as GameObject;
 
         pointer.transform.SetParent(canvas.transform, true);
     }

$$anonymous$$y GameObject will call this function like that:

 drawPlacePoint(hit.point);

hit is place of plane where I have clicked with my mouse.

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

27 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

Related Questions

I Have a Button in Canvas, i Click anywhere except the button and it gets clicked 0 Answers

Draw a Sprite Round 1 Answer

How can I make nested UI Image elements the same transparency? 1 Answer

How would I display a partial image on a canvas in the new UI system? 1 Answer

UI fade with CanvasGroup vs of Image.color.alpha or Text.color.alpha performance 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