unity3d-gui

Unity3D: How to change Transform's (GameObject's) color?

狂风中的少年 提交于 2020-01-17 05:07:53
问题 In old versions of Unity Component's renderer had material, now UnityEngine.Renderer has material, but Component.renderer doesn't have. How can I change the color of my object? private Transform myTransform; ... private void changeColor() { myTransform.renderer.**material**.color = Color.red; // renderer doesn't have *material* } 回答1: By this thread, try GetComponent<Renderer>().material.color = Color.black; 来源: https://stackoverflow.com/questions/33007575/unity3d-how-to-change-transforms

Why material added to ui panel is not visible in android build but works fine in editor window in unity3d?

微笑、不失礼 提交于 2020-01-06 06:47:21
问题 The material added to the UI Panel is working in the editor window but not working in android build. How to fix this? Editor Screenshot Android screenshot Note: I have tried adding a shader to "always Included shader" list in the project setting menu. still not fixed. I'm not altering the shader/material in the code. This is worked fine in a previous unity version. (my unity version is 2018.3.11f1) The same material works fine in other game objects (like a cube, etc,.), but not works with any

4.6 New UI How to change Button Image?

拥有回忆 提交于 2019-12-30 05:01:05
问题 Everything I search is based on the old UI. I've tried the following button.image = Resource.Load<Image>("..."); button.GetComponent<Image>() = Resources.Load<Image>("...."); button.GetComponent<Button>().image = Resources.Load<Image>("...."); button.GetComponent<Image>().sprite = Resources.Load<Sprite>("...."); I want to change the button image on an event. 回答1: Tested and Working. public Sprite myImage; public Button myBtn; void Start(){ myImage = Resources.Load<Sprite>("BTNS"); // Make

Unity3D - Move UI object to center of screen while maintaining its parenting

蹲街弑〆低调 提交于 2019-12-24 07:10:06
问题 I have an UI image that is parented to a RectTransform container, which is parented to a UI panel, which is parented to a Canvas. I want to be able to move this UI image to the center of the screen (ie. canvas) while leaving the parenting hierarchy. My goal is to animate the UI image from the center to where it is now. Can you please let me know what this code would look like? 回答1: To answer your original question, you can place the UICell at the center of the screen using: private

Unity3d with vuforia showing 2d image when targed is detected

拥有回忆 提交于 2019-12-13 04:47:30
问题 I have a question about the way how to show simple 2d image on top of detected marker. I have followed some tutorial to show 3d model and it works fine. there is no problem with 3d. The problem starts when I want to add normal 2d object->sprite . When I add simple sprite I can't add texture and when I insert UI image it's added together with canvas and it is not showed when target is detected. The original image on editor is placed then so far that it's difficult to find it. I would be

Registering Touch on UI in Unity

蹲街弑〆低调 提交于 2019-12-12 03:17:41
问题 I'm needing to have some funcitonality ignored, if I have happen to touch my UI. However, I am struggling to detect if I am actually touching it or not. My UI makes use of the native UI inside Unity. My thought behind it was to simply check the layers and if I touched anything on that layer, I'd stop any functionality from happening. So I wrote this to test it: void Update () { if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) { Ray ray = Camera.main.ScreenPointToRay(

Putting money.text in my shop scene

心已入冬 提交于 2019-12-11 17:17:49
问题 I want my money.text to be in my shop scene to buy some shield. For some reason my money.text is only on the other scene and it's not going in the shop scene. This is my shop script. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class ShopController : MonoBehaviour { int MoneyAmount; int isPowerup1Sold,isPowerup2Sold,isPowerup3Sold; public Text MoneyAmountText; public Button Buynow1,Buynow2

Unity3d how to change UI.Button text in code

痞子三分冷 提交于 2019-12-11 10:37:29
问题 Simple question, I am trying to making a flappy bird clone and I need help displaying score. I have the score being added and displayed to the console, but I cant get it to show on a gui text. I've tried to google how to do this and watch a lot of people's flappy bird tutorials to see how they did it, but all them are before unity 4.6 when they introduced the new ui system, and the same code they use does not seem to work. So how can I access my gui text that is attached to my game object in

Detecting which UI button was pressed within canvas?

北城以北 提交于 2019-12-10 12:19:46
问题 I have like 10 buttons on my UI and I gotta check which one was touched. I was using the following logic and it was working fine, but now I am getting this error for some reason: NullReferenceException: Object reference not set to an instance of an object DetectButton.Start () (at Assets/Scripts/DetectButton.cs:14) Any ideas what could be going on? Here is my code (attached to the canvas), and I am using Unity version 5.1.0f3. If you need any other info I will gladly provide, thanks in

Masking in World Space canvas - Gameobject renderers act as mask too

偶尔善良 提交于 2019-12-08 09:13:01
问题 My goal was to create a Scroll Rect on a worldspace canvas but whenever I would mask out the content everything vanished. I tested on an overlay canvas to see if I was setting it up correctly and I was. What I learned was that non-UI gameobject renderers were being used as the mask too so if there was something being rendered in world space, it would mask the Scroll Rect Content. The top image shows the mask disabled. The bottom shows the mask enabled. Any ideas how I can have it ignore the