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 Dok101 · Aug 27, 2015 at 08:53 AM · uierrorpositionimageanchor

Moving a UI image by script

Hey
Right now I'm creating a menu using Unity and the UI system from 4.6. Basically I'm trying to make it so that if I press down then a certain image will move down to a specified position and if I press up it will go up again.
I've tried the GetComponent.anchoredPosition route, and I tried something like this using UnityEngine; using System.Collections; using UnityEngine.UI; public class Menu_Selection_Indicator : MonoBehaviour { Image [] images01; Image [] images02; int i = 0; void MakeActive (){ for( i = 0;i<6;i++){ %|1898136422_1|% images02[i].enabled = true; } } void Update () { images01.enabled = false; images02.enabled = false; if (Input.GetKeyDown("up")) { %|1096323275_3|% } if (Input.GetKeyDown("down")) { %|341979072_4|% } if (i>5) { %|-1306517619_5|% } if (i<1) { %|-1248293269_2|% } images01[i].enabled = true; images02[i].enabled = true; %|679944723_3|% } }

And although this isn't ideal because of the performance issues for having to turn on and off 10 different images, even this doesn't work, with me getting the errors "Assets/Scripts/CSharpScripts/Menu_Selection_Indicator.cs(41,13): error CS1061: Type UnityEngine.UI.Image' does not contain a definition for SetActive' and no extension method SetActive' of type UnityEngine.UI.Image' could be found (are you missing a using directive or an assembly reference?)"

and "Assets/Scripts/CSharpScripts/Menu_Selection_Indicator.cs(23,10): error CS1061: Type UnityEngine.UI.Image[]' does not contain a definition for SetActive' and no extension method SetActive' of type UnityEngine.UI.Image[]' could be found (are you missing a using directive or an assembly reference?)"
So my question is does anyone know of a way where I could just move my UI image's anchored position from one Vector to another.

Thank you

Dok

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
1

Answer by palash_bhowmick1 · Aug 27, 2015 at 09:27 AM

There is no SetActive in your script... So how can it give according to the script you posted...

If you want to deactivate anything, you need to deactivate the gameObject not the component.. For example,

images01[1].gameObject.setActive(false);

this will work

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 Dok101 · Aug 27, 2015 at 09:17 PM 0
Share

Thank you for your answer
The question however is how I could move it using the anchoredPosition $$anonymous$$ethod.
Thank you

Dok

Edit : I just realised I probably didn't word the end very well. Sorry for any inconvenience

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

29 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

Related Questions

this code doesnt work when the buttons anchor are not same(custom anchor) 0 Answers

how to swap image position 3 Answers

How to get height of filled image ? 1 Answer

How to snap UI element anchor relative to image sprite? 2 Answers

Have UI image float over a gameobject position 0 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