- Home /
Cannot modify a value type return value of...
I know in C# you have to store temporary values, but I'm not sure what I'm missing here.
Error: Assets/NPCs/Scripts/Gorilla.cs(52,38): error CS1612: Cannot modify a value type return value of `UnityEngine.GUITexture.pixelInset'. Consider storing the value in a temporary variable
code:
using UnityEngine; using System.Collections;
/** Random level by 1-2, give bonuses based on level, use switch statement */
public class Gorilla : MonoBehaviour {
GUITexture healthBar;
PlayerStats playerStats;
public int currentHealth, maxHealth, level, minDamage, maxDamage, expGain;
public float hitRate;
// Use this for initialization
void Start () {
playerStats = GameObject.Find("Player").GetComponent<PlayerStats>();
level = Random.Range(1, 2);
switch(level) {
case 0:
case 1:
maxHealth = 100;
minDamage = 3;
maxDamage = 9;
hitRate = 80.0f;
expGain = 40;
break;
case 2:
maxHealth = 120;
minDamage = 5;
maxDamage = 12;
hitRate = 85.0f;
expGain = 50;
break;
}
currentHealth = maxHealth;
}
// Update is called once per frame
void Update () {
int hpPercent = (int)(currentHealth / maxHealth);
int hpBarLength = hpPercent * 100;
if(currentHealth < 1) {
GameObject.Destroy(this);
playerStats.currentExperience += expGain;
return;
}
healthBar.guiTexture.pixelInset.width = hpBarLength;
}
}
Answer by ExTheSea · May 10, 2013 at 10:19 AM
Check out this link. They talk about storing the pixelInset value in a Rect and modify the width using the Rect.
Like this:
Rect insetRect = healthBar.guiTexture.pixelInset;
insetRect.width = hpBarLength;
healthbar.guiTexture.pixelInset = insetRect;
No link, but it compiles, thanks. Couldn't figure out what exactly it was that I was trying to store.
But, the HPBar isn't showing, but that's probably some other problem
Sry. I meant to paste this link here:
http://forum.unity3d.com/threads/72695-C-Passing-a-value-to-pixelInset-x$$anonymous$$ax-struct
Ah, thanks. I got it all working, but my $$anonymous$$onoDevelop stopped working! Fudge.
Ah right your question popped up in my mail inbox.
$$anonymous$$aybe some of these links may help in your case although i don't know as i never had such a problem:
http://forum.unity3d.com/threads/116523-$$anonymous$$onodevelop-Doesn-t-Open
http://answers.unity3d.com/questions/206019/why-built-in-monodevelop-for-unity-doesnt-launch.html
Your answer
Follow this Question
Related Questions
How do you CORRECTLY call methods from another C# file 1 Answer
Using GUI skin with my GUI Button 1 Answer
Using GUI and GUILayout at the same time 1 Answer
creating a list of texture2d components 0 Answers
FPS keep a loadout 0 Answers