GUITexture is deprecated, so what should I use instead of it?
I'm currently experiencing an issue with updated coding in C#. I'm working out of a textbook "3.x Game Development Essentials", and am currently attempting to make an array that will have textures assigned to it which will show the progression of a battery being charged to power a door. The textbook wants me to create a GUITexture, however this was made obsolete in a prior Unity update so I instead created a UI Image which created a Canvas and a child Game Object. While this fixed the problem on screen, it took a turn for the worse with coding. The book wants me to create an array of five textures (four states of charge, plus the original empty texture). The goal being whenever the character picks up a power cell, it reflects live in the UI Canvas. Now, here's where I get goobery:
This is the original coding the book specifies to implement on my Inventory script:
public Texture2D hudCharge;
public GUITexture charge HudGUI;
I ended up having to get squirrelly to work around old code, and tried this:
using UnityEngine.UI;
public class Inventory : MonoBehaviour{
public static int charge = 0
public UnityEngine.AudioClip collectSound;
public UnityEngine.Texture2D hudCharge;
public Image chargeHudGUI;
Now we get even weirder.
Because the book is working with out of date code, it wants me to use the value of charge to choose a texture from the array. Thus, it wants me to type:
chargeHudGUI.texture = hudCharge[charge];
the goal being We're addressing the GUITexture object that is assigned to chargeHudGUI variable, specifically its texture property. Well, that'd be groovy but there's no GUITexture anymore so where does that leave me? It leaves me with this:
chargeHudGUI.Image = hudCharge[charge].
I have been looking through every thread I can to try and figure out what to do, but nothing seems to address this particular problem. Does anyone have any pointers for navigating around this nonsense? I've been working on this game for a while now, and I'm determined to finish it out. I want to learn how to use Visual Studio and Unity3D. I appreciate any help!
c# visual-studio user-interface unity3d guitexture
add a comment |
I'm currently experiencing an issue with updated coding in C#. I'm working out of a textbook "3.x Game Development Essentials", and am currently attempting to make an array that will have textures assigned to it which will show the progression of a battery being charged to power a door. The textbook wants me to create a GUITexture, however this was made obsolete in a prior Unity update so I instead created a UI Image which created a Canvas and a child Game Object. While this fixed the problem on screen, it took a turn for the worse with coding. The book wants me to create an array of five textures (four states of charge, plus the original empty texture). The goal being whenever the character picks up a power cell, it reflects live in the UI Canvas. Now, here's where I get goobery:
This is the original coding the book specifies to implement on my Inventory script:
public Texture2D hudCharge;
public GUITexture charge HudGUI;
I ended up having to get squirrelly to work around old code, and tried this:
using UnityEngine.UI;
public class Inventory : MonoBehaviour{
public static int charge = 0
public UnityEngine.AudioClip collectSound;
public UnityEngine.Texture2D hudCharge;
public Image chargeHudGUI;
Now we get even weirder.
Because the book is working with out of date code, it wants me to use the value of charge to choose a texture from the array. Thus, it wants me to type:
chargeHudGUI.texture = hudCharge[charge];
the goal being We're addressing the GUITexture object that is assigned to chargeHudGUI variable, specifically its texture property. Well, that'd be groovy but there's no GUITexture anymore so where does that leave me? It leaves me with this:
chargeHudGUI.Image = hudCharge[charge].
I have been looking through every thread I can to try and figure out what to do, but nothing seems to address this particular problem. Does anyone have any pointers for navigating around this nonsense? I've been working on this game for a while now, and I'm determined to finish it out. I want to learn how to use Visual Studio and Unity3D. I appreciate any help!
c# visual-studio user-interface unity3d guitexture
add a comment |
I'm currently experiencing an issue with updated coding in C#. I'm working out of a textbook "3.x Game Development Essentials", and am currently attempting to make an array that will have textures assigned to it which will show the progression of a battery being charged to power a door. The textbook wants me to create a GUITexture, however this was made obsolete in a prior Unity update so I instead created a UI Image which created a Canvas and a child Game Object. While this fixed the problem on screen, it took a turn for the worse with coding. The book wants me to create an array of five textures (four states of charge, plus the original empty texture). The goal being whenever the character picks up a power cell, it reflects live in the UI Canvas. Now, here's where I get goobery:
This is the original coding the book specifies to implement on my Inventory script:
public Texture2D hudCharge;
public GUITexture charge HudGUI;
I ended up having to get squirrelly to work around old code, and tried this:
using UnityEngine.UI;
public class Inventory : MonoBehaviour{
public static int charge = 0
public UnityEngine.AudioClip collectSound;
public UnityEngine.Texture2D hudCharge;
public Image chargeHudGUI;
Now we get even weirder.
Because the book is working with out of date code, it wants me to use the value of charge to choose a texture from the array. Thus, it wants me to type:
chargeHudGUI.texture = hudCharge[charge];
the goal being We're addressing the GUITexture object that is assigned to chargeHudGUI variable, specifically its texture property. Well, that'd be groovy but there's no GUITexture anymore so where does that leave me? It leaves me with this:
chargeHudGUI.Image = hudCharge[charge].
I have been looking through every thread I can to try and figure out what to do, but nothing seems to address this particular problem. Does anyone have any pointers for navigating around this nonsense? I've been working on this game for a while now, and I'm determined to finish it out. I want to learn how to use Visual Studio and Unity3D. I appreciate any help!
c# visual-studio user-interface unity3d guitexture
I'm currently experiencing an issue with updated coding in C#. I'm working out of a textbook "3.x Game Development Essentials", and am currently attempting to make an array that will have textures assigned to it which will show the progression of a battery being charged to power a door. The textbook wants me to create a GUITexture, however this was made obsolete in a prior Unity update so I instead created a UI Image which created a Canvas and a child Game Object. While this fixed the problem on screen, it took a turn for the worse with coding. The book wants me to create an array of five textures (four states of charge, plus the original empty texture). The goal being whenever the character picks up a power cell, it reflects live in the UI Canvas. Now, here's where I get goobery:
This is the original coding the book specifies to implement on my Inventory script:
public Texture2D hudCharge;
public GUITexture charge HudGUI;
I ended up having to get squirrelly to work around old code, and tried this:
using UnityEngine.UI;
public class Inventory : MonoBehaviour{
public static int charge = 0
public UnityEngine.AudioClip collectSound;
public UnityEngine.Texture2D hudCharge;
public Image chargeHudGUI;
Now we get even weirder.
Because the book is working with out of date code, it wants me to use the value of charge to choose a texture from the array. Thus, it wants me to type:
chargeHudGUI.texture = hudCharge[charge];
the goal being We're addressing the GUITexture object that is assigned to chargeHudGUI variable, specifically its texture property. Well, that'd be groovy but there's no GUITexture anymore so where does that leave me? It leaves me with this:
chargeHudGUI.Image = hudCharge[charge].
I have been looking through every thread I can to try and figure out what to do, but nothing seems to address this particular problem. Does anyone have any pointers for navigating around this nonsense? I've been working on this game for a while now, and I'm determined to finish it out. I want to learn how to use Visual Studio and Unity3D. I appreciate any help!
c# visual-studio user-interface unity3d guitexture
c# visual-studio user-interface unity3d guitexture
edited Nov 27 '18 at 2:20
Programmer
77.2k1089158
77.2k1089158
asked Nov 27 '18 at 1:48
L. DostalL. Dostal
484
484
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
GUITexture
is indeed deprecated just like GUIText . Since your hudCharge
variable is a type of Texture2D
, make chargeHudGUI
to be type of RawImage
instead of Image
so that you can assign it directly with the texture property.
Go to GameObject ---> UI ---> RawImage and Unity will create a Canvas with a GameObject as a child. That child GameObject will have a RawImage
component. You can learn more about the new UI system here.
So, replace
public Image chargeHudGUI;
with
public RawImage chargeHudGUI;
Now, you can do this:
chargeHudGUI.texture = hudCharge[charge];
You can still use Image
instead of RawImage
but you have to convert the Texture2D
to Sprite
each time or cache them then change the Image.sprite
property to display them.
public Image chargeHudGUI;
then you can do this:
Texture2D tex = hudCharge[charge];
//Create Sprite from the Texture2D
Sprite tempSprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
//Change the Sprite
chargeHudGUI.sprite = tempSprite;
1
HA! I knew there was a loophole in the system somewhere. From now on I'll do RawImage instead of Image when I want to get involved with Textures. I'm going to follow the link you gave and read up about the new UI system. Hopefully I can manage to get around more kinks in the future. You're the best. <3
– L. Dostal
Nov 27 '18 at 2:42
1
Also, make sure to remove any function calledOnGUI
as that as well is the old UI system. The link I provided should help you get started on the new UI system. When it comes to detecting clicks on them which you'll need to do in the future, see this post. You're welcome.
– Programmer
Nov 27 '18 at 2:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491613%2fguitexture-is-deprecated-so-what-should-i-use-instead-of-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
GUITexture
is indeed deprecated just like GUIText . Since your hudCharge
variable is a type of Texture2D
, make chargeHudGUI
to be type of RawImage
instead of Image
so that you can assign it directly with the texture property.
Go to GameObject ---> UI ---> RawImage and Unity will create a Canvas with a GameObject as a child. That child GameObject will have a RawImage
component. You can learn more about the new UI system here.
So, replace
public Image chargeHudGUI;
with
public RawImage chargeHudGUI;
Now, you can do this:
chargeHudGUI.texture = hudCharge[charge];
You can still use Image
instead of RawImage
but you have to convert the Texture2D
to Sprite
each time or cache them then change the Image.sprite
property to display them.
public Image chargeHudGUI;
then you can do this:
Texture2D tex = hudCharge[charge];
//Create Sprite from the Texture2D
Sprite tempSprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
//Change the Sprite
chargeHudGUI.sprite = tempSprite;
1
HA! I knew there was a loophole in the system somewhere. From now on I'll do RawImage instead of Image when I want to get involved with Textures. I'm going to follow the link you gave and read up about the new UI system. Hopefully I can manage to get around more kinks in the future. You're the best. <3
– L. Dostal
Nov 27 '18 at 2:42
1
Also, make sure to remove any function calledOnGUI
as that as well is the old UI system. The link I provided should help you get started on the new UI system. When it comes to detecting clicks on them which you'll need to do in the future, see this post. You're welcome.
– Programmer
Nov 27 '18 at 2:47
add a comment |
GUITexture
is indeed deprecated just like GUIText . Since your hudCharge
variable is a type of Texture2D
, make chargeHudGUI
to be type of RawImage
instead of Image
so that you can assign it directly with the texture property.
Go to GameObject ---> UI ---> RawImage and Unity will create a Canvas with a GameObject as a child. That child GameObject will have a RawImage
component. You can learn more about the new UI system here.
So, replace
public Image chargeHudGUI;
with
public RawImage chargeHudGUI;
Now, you can do this:
chargeHudGUI.texture = hudCharge[charge];
You can still use Image
instead of RawImage
but you have to convert the Texture2D
to Sprite
each time or cache them then change the Image.sprite
property to display them.
public Image chargeHudGUI;
then you can do this:
Texture2D tex = hudCharge[charge];
//Create Sprite from the Texture2D
Sprite tempSprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
//Change the Sprite
chargeHudGUI.sprite = tempSprite;
1
HA! I knew there was a loophole in the system somewhere. From now on I'll do RawImage instead of Image when I want to get involved with Textures. I'm going to follow the link you gave and read up about the new UI system. Hopefully I can manage to get around more kinks in the future. You're the best. <3
– L. Dostal
Nov 27 '18 at 2:42
1
Also, make sure to remove any function calledOnGUI
as that as well is the old UI system. The link I provided should help you get started on the new UI system. When it comes to detecting clicks on them which you'll need to do in the future, see this post. You're welcome.
– Programmer
Nov 27 '18 at 2:47
add a comment |
GUITexture
is indeed deprecated just like GUIText . Since your hudCharge
variable is a type of Texture2D
, make chargeHudGUI
to be type of RawImage
instead of Image
so that you can assign it directly with the texture property.
Go to GameObject ---> UI ---> RawImage and Unity will create a Canvas with a GameObject as a child. That child GameObject will have a RawImage
component. You can learn more about the new UI system here.
So, replace
public Image chargeHudGUI;
with
public RawImage chargeHudGUI;
Now, you can do this:
chargeHudGUI.texture = hudCharge[charge];
You can still use Image
instead of RawImage
but you have to convert the Texture2D
to Sprite
each time or cache them then change the Image.sprite
property to display them.
public Image chargeHudGUI;
then you can do this:
Texture2D tex = hudCharge[charge];
//Create Sprite from the Texture2D
Sprite tempSprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
//Change the Sprite
chargeHudGUI.sprite = tempSprite;
GUITexture
is indeed deprecated just like GUIText . Since your hudCharge
variable is a type of Texture2D
, make chargeHudGUI
to be type of RawImage
instead of Image
so that you can assign it directly with the texture property.
Go to GameObject ---> UI ---> RawImage and Unity will create a Canvas with a GameObject as a child. That child GameObject will have a RawImage
component. You can learn more about the new UI system here.
So, replace
public Image chargeHudGUI;
with
public RawImage chargeHudGUI;
Now, you can do this:
chargeHudGUI.texture = hudCharge[charge];
You can still use Image
instead of RawImage
but you have to convert the Texture2D
to Sprite
each time or cache them then change the Image.sprite
property to display them.
public Image chargeHudGUI;
then you can do this:
Texture2D tex = hudCharge[charge];
//Create Sprite from the Texture2D
Sprite tempSprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
//Change the Sprite
chargeHudGUI.sprite = tempSprite;
edited Nov 28 '18 at 0:39
answered Nov 27 '18 at 2:19
ProgrammerProgrammer
77.2k1089158
77.2k1089158
1
HA! I knew there was a loophole in the system somewhere. From now on I'll do RawImage instead of Image when I want to get involved with Textures. I'm going to follow the link you gave and read up about the new UI system. Hopefully I can manage to get around more kinks in the future. You're the best. <3
– L. Dostal
Nov 27 '18 at 2:42
1
Also, make sure to remove any function calledOnGUI
as that as well is the old UI system. The link I provided should help you get started on the new UI system. When it comes to detecting clicks on them which you'll need to do in the future, see this post. You're welcome.
– Programmer
Nov 27 '18 at 2:47
add a comment |
1
HA! I knew there was a loophole in the system somewhere. From now on I'll do RawImage instead of Image when I want to get involved with Textures. I'm going to follow the link you gave and read up about the new UI system. Hopefully I can manage to get around more kinks in the future. You're the best. <3
– L. Dostal
Nov 27 '18 at 2:42
1
Also, make sure to remove any function calledOnGUI
as that as well is the old UI system. The link I provided should help you get started on the new UI system. When it comes to detecting clicks on them which you'll need to do in the future, see this post. You're welcome.
– Programmer
Nov 27 '18 at 2:47
1
1
HA! I knew there was a loophole in the system somewhere. From now on I'll do RawImage instead of Image when I want to get involved with Textures. I'm going to follow the link you gave and read up about the new UI system. Hopefully I can manage to get around more kinks in the future. You're the best. <3
– L. Dostal
Nov 27 '18 at 2:42
HA! I knew there was a loophole in the system somewhere. From now on I'll do RawImage instead of Image when I want to get involved with Textures. I'm going to follow the link you gave and read up about the new UI system. Hopefully I can manage to get around more kinks in the future. You're the best. <3
– L. Dostal
Nov 27 '18 at 2:42
1
1
Also, make sure to remove any function called
OnGUI
as that as well is the old UI system. The link I provided should help you get started on the new UI system. When it comes to detecting clicks on them which you'll need to do in the future, see this post. You're welcome.– Programmer
Nov 27 '18 at 2:47
Also, make sure to remove any function called
OnGUI
as that as well is the old UI system. The link I provided should help you get started on the new UI system. When it comes to detecting clicks on them which you'll need to do in the future, see this post. You're welcome.– Programmer
Nov 27 '18 at 2:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491613%2fguitexture-is-deprecated-so-what-should-i-use-instead-of-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown