- Home /
Changing RawImage position killing frame rate on Android
Well the question is self explanatory, i m changing the RawImage.position
in Update
method and this is killing my frame rate and one of my level is not changing position as it doesn't have any RawImage in it and it is running smoothly, this means it RawImage.position
which is dropping my frame rate ... basically i want background of my 2D game to move in random directions so i used RawImage and changing its position through script ... below is my script ...
public RawImage cieRawImageTop, cieRawImageBottom;
private Vector2 offsetTop, offsetBottom;
private float speed;
private Rect tempRectTop, tempRectBottom;
private uint currNum, newNum;
void Start(){
speed = 0.0002f;
setTopDirection ();
}
void Update () {
tempRectTop.position = cieRawImageTop.uvRect.position + offsetTop;
cieRawImageTop.uvRect = tempRectTop;
tempRectBottom.position = cieRawImageBottom.uvRect.position + offsetBottom;
cieRawImageBottom.uvRect = tempRectBottom;
}
void setTopDirection(){
offsetTop = setDirection ();
Invoke ("setBottomDirection", 1f);
}
void setBottomDirection(){
offsetBottom = setDirection ();
Invoke ("setTopDirection", 4f);
}
Vector2 setDirection(){
Vector2 newOffset = new Vector2 (0f, 0f);
newNum = (uint)Random.Range (0, 8);
switch (newNum) {
case 0:
newOffset.x = 0f;
newOffset.y = -speed;
break;
case 1:
newOffset.x = speed;
newOffset.y = -speed;
break;
case 2:
newOffset.x = speed;
newOffset.y = 0f;
break;
case 3:
newOffset.x = newOffset.y = speed;
break;
case 4:
newOffset.x = 0f;
newOffset.y = speed;
break;
case 5:
newOffset.x = -speed;
newOffset.y = speed;
break;
case 6:
newOffset.x = -speed;
newOffset.y = 0f;
break;
case 7:
newOffset.x = newOffset.y = -speed;
break;
}
return newOffset;
}
Answer by aditya · Apr 25, 2016 at 07:21 AM
Okay ... i got it working myself ... so for anyone who facing same issue there are two things to consider here ... one is the size of your texture, the texture i used before was of size 800 - 1280 which i deducted to 360 - 640 and second and probably the most important, if you bring down the alpha of UI elements from unity editor (or play with this ALPHA thingy through scripts) this will kill your frame rate, so what i did is that i made texture with alpha pre decided and make the alpha full through unity editor
Your answer
![](https://koobas.hobune.stream/wayback/20220612075546im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Component name for raw image. 1 Answer
UI Escape menu script not working. 2 Answers
C#: Generate Raw File from byte[]? 1 Answer