Swipe over table in mobile browser - mobile

I and my teammate are writing the game "Battlecity" in dart for mobile browser. The problem is with swipes for tank direction(left to right, right to left, etc) in mobile browser. It works with a great delation(and for some reasond doesn't works in Chrome-Browser).
You can see the problem better, if you start the game on your mobile device(just open link with game: https://javajunikorn.github.io/BattleCity/build/web/html/test.html)
Interesting thing is, that the problem exists only on swipes over gamefield(in our case it's 27*27 html table). If we're swiping out of gamefeeld, than it works great.
Here is code of our Controller:
class Direction{
Point first, last;
Game game;
void startListening(){
window.onTouchStart.listen((ev) {
last = null;
first = ev.touches.first.client;
});
window.onTouchMove.listen((ev){
last = ev.touches.first.client;
});
window.onTouchEnd.listen((ev) {
if(last == null || first.distanceTo(last) < 20)
game.player.shoot();
else {
Point d = first - last;
if(d.x.abs() > d.y.abs()){
//Waagerecht
if( first.x > last.x){
//links
game.player.changeDirection(Directions.left);
}
else{
//rechts
game.player.changeDirection(Directions.right);
}
}
else{
//Senkrecht
if(first.y > last.y){
//Up
game.player.changeDirection(Directions.up);
}
else{
//Down
game.player.changeDirection(Directions.down);
}
}
}
});
window.onKeyPress.listen((k) {
//Shoot
if(k.which == 32) { //spacebar
game.player.shoot();
}
//Up
if(k.which == 119 || k.keyCode == KeyCode.UP){
game.player.changeDirection(Directions.up);
}
//Down
if(k.which == 115 || k.keyCode == KeyCode.DOWN){
game.player.changeDirection(Directions.down);
}
//Left
if(k.which == 97 || k.keyCode == KeyCode.LEFT){
game.player.changeDirection(Directions.left);
}
//Right
if(k.which == 100 || k.keyCode == KeyCode.RIGHT){
game.player.changeDirection(Directions.right);
}
});
}
}

Related

Why is my C program not counting correctly? Card game

I've created a card game that compares two cards of two players and determines a winner based on certain conditions. I have a function that compares the cards and returns true or false depending on the winner of the round. I call it inside a loop in my function that runs the game and the number of iterations is based on the number of cards dealt to each player. Theres something with my compare card function that allows for some rounds to fail comparison tests and I cannot tell why. The result is that my players win counts are off at the end of the game. Ive tried playing with the conditions at various points but I cannot find the issue.
Compare cards function - on seemingly random rounds the print condition at the end will execute telling me I've slipped through the other conditions
bool compareCards(char *card1, char *card2)
{
char card1Face = card1[0];
char card2Face = card2[0];
//if card1 is A/K/Q/J and card2 is num
if ((card1Face >= 'A' && card1Face <= 'Z') && !(card2Face >= 'A' && card2Face <= 'Z'))
{
return true;
}
//if card1 is num and card2 is A/K/Q/J
else if (!(card1Face >= 'A' && card1Face <= 'Z') && (card2Face >= 'A' && card2Face <= 'Z'))
{
return false;
}
//if card1 and card2 both A/K/Q/J
else if ((card1Face >= 'A' && card1Face <= 'Z') && (card2Face >= 'A' && card2Face <= 'Z'))
{
//test for A
if (card1Face == 'A' && card2Face != 'A')
{
return true;
}
else if (card1Face != 'A' && card2Face == 'A')
{
return false;
}
//test for K
if (card1Face == 'K' && card2Face != 'K')
{
return true;
}
else if (card1Face != 'K' && card2Face == 'K')
{
return false;
}
//test for Q
if (card1Face == 'Q' && card2Face != 'Q')
{
return true;
}
else if (card1Face != 'Q' && card2Face == 'Q')
{
return false;
}
//test for J
if (card1Face == 'J' && card2Face != 'J')
{
return true;
}
else if (card1Face != 'J' && card2Face == 'J')
{
return false;
}
} //end cards are face cards
//If card1 and card2 are nums
else if ((card1Face >= '1' && card1Face <= '9') && (card2Face >= '1' && card2Face <= '9'))
{
//if card1 is 10 and card2 is not
if (card1Face == '1' && card2Face != '1')
{
return true;
}
//if card2 is 10 and card1 is not
else if (card1Face != '1' && card2Face == '1')
{
return false;
}
//if card1 higher than card2
else if (card1Face > card2Face)
{
return true;
}
//if card1 lower than card2
else if (card1Face < card2Face)
{
return false;
}
} //end cards are nums
//if card1 and card2 same face value
else if (card1Face == card2Face)
{
char card1Suit = card1[strlen(card1) - 1];
char card2Suit = card2[strlen(card2) - 1];
//test for spade
if (card1Suit == 'S')
{
return true;
}
else if (card2Suit == 'S')
{
return false;
}
//test for Hearts
if (card1Suit == 'H')
{
return true;
}
else if (card2Suit == 'H')
{
return false;
}
//test for Diamonds
if (card1Suit == 'D')
{
return true;
}
else if (card2Suit == 'D')
{
return false;
}
//test for Clubs
if (card1Suit == 'C')
{
return true;
}
else if (card2Suit == 'C')
{
return false;
}
}
printf("IF THIS PRINTS UH OH");
return EXIT_SUCCESS;
}
The main playGame function
void playGame(void)
{
srand(time(NULL));
//initialize deck
char *(*deck)[13] = initializeDeck();
deck = shuffleDeck(deck);
bool quit = false;
while (1)
{
printHeaderDeal();
//user input loop
while (1)
{
fflush(stdin);
char choice = getchar();
//if enter to deal
if (choice == '\n')
{
break;
}
//if q to quit
else if (choice == 'q' || choice == 'Q')
{
printf("You chose to quit\n");
quit = true;
break;
}
//handling wrong input
else
{
printf("Incorrect choice! Please choose ENTER to deal or q to quit. \n");
scanf("%*[^\n]%*c");
}
} //end user input
//if quit selected break from loop
if (quit == true)
{
break;
}
int numCardsToDeal;
//user selects number of cards to deal
while (1)
{
printf("How many cards would you like to deal? 2-20\n");
scanf(" %d", &numCardsToDeal);
scanf("%*[^\n]");
//set range = even number between 2-20
if (numCardsToDeal >= 2 && numCardsToDeal <= 20)
{
if (numCardsToDeal % 2 == 1)
{
printf("Players must have same amount of cards in hand. Pick an even amount to deal.\n");
}
else
{
break;
}
}
else
{
printf("Incorrect selection.\n");
}
}//end num to deal selection and validation
//call deal cards and subtract the return value from the remaining card total
cardsRemaining -= dealCards(deck, numCardsToDeal);
bool result;
Here is where I print the players hands, call the compare function and count the wins based on each round
int length1 = sizeof(player1Hand)/sizeof(player1Hand[0]);
printf("\n\n");
printf("Player 1 hand: ");
for(int i = 0; i < length1; i++)
{
printf("[%s]", player1Hand[i]);
}
printf("\n\n");
int length2 = sizeof(player2Hand)/sizeof(player2Hand[0]);
printf("Player 2 hand: ");
for(int i = 0; i < length2; i++)
{
printf("[%s]", player2Hand[i]);
}
printf("\n\n");
//loop through player hands based on num of dealt cards, call compareCards on each iteration and store results of each comparison
for (int i = 0; i < (numCardsToDeal / 2); i++)
{
result = compareCards(player1Hand[i], player2Hand[i]);
if (result == true)
{
player1Wins++;
}
else if (result == false)
{
player2Wins++;
}
}
//if run out of cards end game
if (cardsRemaining == 0)
{
printf("No more cards remaining in deck. Game over.\n\n");
break;
}
} //end game
printf("Total wins for player 1: %d\n", player1Wins);
printf("Total wins for player 2: %d\n", player2Wins);
free(deck);
}
I'm not sure if this will actually solve the issue, but this is too long for a comment:
There may be some other logic issues, but the first thing I've noticed is in your test for cards with numbers:
//If card1 and card2 are nums
else if ((card1Face >= '1' && card1Face <= '9') && (card2Face >= '1' && card2Face <= '9'))
{
// snipped
} //end cards are nums
If card1Face and card2Face are both the same number, no condition will match, so it will fall through.
Note, that even though you have another else if test for if the cards are equal, that's below this case and will NOT be run, because you've already matched one else if condition.
So, this may not fix the issue completely, but I think if you move the check for card1Face == card2Face up to be one of the earlier checks, then you can at least remove a few cases where it will not work as you're expecting. Actually, I think you should make the equal card check the first check; make the if condition card1Face == card2Face, then all of the others to be else if.
Finally, for the sake of debugging, if it's still not working properly after that change, add an else block that just prints the two card values; you may start to see a pattern which will help find where other problems might be occurring.

Efficiently navigating arrays and selected strings

I am a noob playing around with actionscript but i feel this question is a basic coding questionMy project is similar to this picture.
I have four quadrant areas (Red, blue, yellow, and green) that I am adding text buttons to each area with a single word in each button. There are 16 words in each section that are added from 4 arrays that have the preset words (redWordArray, greenWordArray, yellowWordArray, blueWordArray). When clicked, the text button glows using a glow filter and the word gets added to another array for data collecting. For instance, a red word when clicked gets added to a red array (redChosenArray). When the word is clicked again, it removes the glow filter and is removed from the chosen array.
I am finding that my performance is slow and I am wondering if I am adding and deleting words correctly and efficiently. These are my functions for adding the glow filters and the selected word to the array. I would love your insights for best coding practices as I am sure it is a mess!
Thank you!
function selectWord(event:MouseEvent):void
{
var tempWord:String = event.currentTarget.mood.text;
var tempArray:Array;
if (event.currentTarget.clicked == false)
{
event.currentTarget.filters = filterArray;
event.currentTarget.clicked = true;
tempArray = addToArray(tempWord)
tempArray.push(tempWord);
trace(redChosen);
trace(blueChosen);
trace(yellowChosen);
trace(greenChosen);
trace("");
}else if(event.currentTarget.clicked == true)
{
event.currentTarget.filters = emptyFilterArray;
event.currentTarget.clicked = false;
removeMoodWord(tempWord);
trace(redChosen);
trace(blueChosen);
trace(yellowChosen);
trace(greenChosen);
trace("");
}
}
function addToArray(moodWord:String):Array
{
var wordFound:Boolean = false;
var allWords:int = 16;
var chosenArray:Array;
while (!wordFound)
{
for (var h:int = 0; h < allWords; h++)
{
if (moodWord == redWords[h])
{
chosenArray = redChosen;
wordFound = true;
}else if (moodWord == yellowWords[h])
{
chosenArray = yellowChosen
wordFound = true;
}else if (moodWord == greenWords[h])
{
chosenArray = greenChosen
wordFound = true;
}else if (moodWord == blueWords[h])
{
chosenArray = blueChosen
wordFound = true;
}
}
}
return chosenArray;
}
function removeMoodWord(moodWord:String):void
{
if (redChosen.indexOf(moodWord) >= 0)
{
redChosen.splice(redChosen.indexOf(moodWord), 1);
}else if (blueChosen.indexOf(moodWord) >= 0)
{
blueChosen.splice(blueChosen.indexOf(moodWord), 1);
}else if (yellowChosen.indexOf(moodWord) >= 0)
{
yellowChosen.splice(yellowChosen.indexOf(moodWord), 1);
}else if (greenChosen.indexOf(moodWord) >= 0)
{
greenChosen.splice(greenChosen.indexOf(moodWord), 1);
}
i fee}

Chrome theme bug Codename One

I got this button to switch themes:
public void onButtonThemeActionEvent(com.codename1.ui.events.ActionEvent ev) {
if(index == 0) {
index++;
UIManager.initNamedTheme("/theme", "Leather");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 1) {
index++;
UIManager.initNamedTheme("/theme", "Chrome");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 2) {
index++;
UIManager.initNamedTheme("/theme", "FlatOrange");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 3) {
index++;
UIManager.initNamedTheme("/theme", "FlatBlue");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 4) {
index++;
UIManager.initNamedTheme("/theme", "FlatRed");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 5) {
index = 0;
UIManager.initNamedTheme("/theme", "Business");
Display.getInstance().getCurrent().refreshTheme();
}
}
This code will change the themes in a sequence as you can see, the problem happens when changing from Leather to Chrome then as you can see in the image below in the Form title is missing a letter "Tela Principa" it should be "Tela Principal" instead.
OBS: This is an Android Device.
Chrome theme missing a letter in the Form title:
After navigating through any menu and backing to Tela Principal, it is fixed as in the following image:
How to fix this Chrome theme bug?
You need to add a revalidate() after switching themes so the UI will update to new font sizes/padding/margin etc.
If that doesn't work try a forceRevalidate() which you shouldn't normally do but is sometimes necessary.

Actionscript 3 - How to Check if an Array Position Already Exists

Hello my question is as stated. I have a randomly generated dungeon with a player and random blocks. All the rooms in the dungeon are saved in the ROOMS 2D array which contains the data for the rooms. You have a current Row and current Col which is where the player is at. What i need to know is how to say IF there is no room above the current position then change the outside wall graphic to close the exits/doors where there is no room. I have this somewhat working but everyway i change it there is always one room which just will not work if i try to add the code. What i have now is abunch of if statements saying IF ROOMS[currentRow + 1][currentCol](< that would be equal to down) so if one row up exists then change the graphic by doing gotoAndStop. So how or which is the best way to determine if a position exists because with this, it will randomly comeback with errors like "term is undefined and has no properties." Also i have really dirty code, sorry im new, ill try to clean it up later but if any of you feel like it, i wont stop you haha!
Im grateful for any replies! Here is my room class
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Room extends MovieClip{
var room1:Array = new Array();
var room2:Array = new Array();
var room3:Array = new Array();
var room4:Array = new Array();
var room5:Array = new Array();
var room6:Array = new Array();
var room7:Array = new Array();
var room8:Array = new Array();
var room9:Array = new Array();
var room10:Array = new Array();
var currentRow:int = 0;
var currentCol:int = 0;
var box:Box;
var boxes:Array;
var ROOMS:Array;
var onTop:Boolean;
var moved:Boolean;
private var player:Player;
private var walls:Walls;
private var blocker1:Blocker;
private var blocker2:Blocker;
private var blocker3:Blocker;
private var blocker4:Blocker;
private var arrowImage:ArrowSymbol;
public function Room(){
init();
createRooms();//add the walls + boxes of first room to the first array value // later make floors array that contains all the rooms and room array that contains all the boxes and enemies + events
stage.addChild(ROOMS[currentRow][currentCol]);
Constants.wallsRef = ROOMS[currentRow][currentCol];
addEventListener(Event.ENTER_FRAME, update);
stage.addChild(arrowCount);
stage.addChild(arrowImage);
}
function init(){
Constants.stageRef=stage;
player = new Player();
//add walls
walls = new Walls();
Constants.wallsRef=walls;
blocker1 = new Blocker();//BLOCKER WHEN PLAYER TOUCHES IT CHANGES ROOM
blocker1.x = 350;
blocker1.y = 1;
stage.addChild(blocker1);
blocker2 = new Blocker();
blocker2.x = 350;
blocker2.y = 619;
stage.addChild(blocker2);
blocker3 = new Blocker();
blocker3.x = -30;
blocker3.y = 300;
blocker3.rotation = 90;
stage.addChild(blocker3);
blocker4 = new Blocker();
blocker4.x = 700;
blocker4.y = 300;
blocker4.rotation = 90;
stage.addChild(blocker4);
Constants.blockerRef1 = blocker1;
Constants.blockerRef2 = blocker2;
Constants.blockerRef3 = blocker3;
Constants.blockerRef4 = blocker4;
//add player
player.x = 300;
player.y = 200;
stage.addChild(player);
arrowImage = new ArrowSymbol();
arrowImage.x = 630;
arrowImage.y = 30;
box = new Box();
boxes = new Array();
ROOMS = new Array([room2],
[room6, room1, room5], /// THIS IS THE MAP OF THE FLOOR /// GOING UP ON THE GAME IS GOING DOWN ON IT
[room7, room8],
[room3, room9],
[room4]);//THIS WILL EVENTUALLY BE COMPLETELY RANDOMIZED//
onTop = false;
moved = false;
}
function update(e:Event){
arrowCount.text = " " + Constants.arrowNumRef;//arrow amount left
closeUnnecessaryExits();
//UP
if(Constants.blockerRef1.hitTestPoint(player.x,player.y) && moved != true){
stage.removeChild(ROOMS[currentRow][currentCol]);//remove the room you are in so the new room doesnt overlap
currentRow++;//change where the player is in
stage.addChild(ROOMS[currentRow][currentCol]);//add new room
Constants.wallsRef = ROOMS[currentRow][currentCol];//add colision
player.y = 600;
stage.addChild(arrowCount);
stage.addChild(arrowImage);
trace();
moved = true;
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
//DOWN
if(Constants.blockerRef2.hitTestPoint(player.x,player.y) && moved != true){
//this will be where i want to change rooms
stage.removeChild(ROOMS[currentRow][currentCol]);
currentRow--;
Constants.wallsRef = ROOMS[currentRow][currentCol];
stage.addChild(ROOMS[currentRow][currentCol]);
player.y = 10;//change to 600
moved = true;
trace("changed rooms");
stage.addChild(arrowCount);
stage.addChild(arrowImage);
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
//LEFT
if(Constants.blockerRef3.hitTestPoint(player.x,player.y) && moved != true){
stage.removeChild(ROOMS[currentRow][currentCol]);//remove the room you are in so the new room doesnt overlap
currentCol--;//change where the player is in
stage.addChild(ROOMS[currentRow][currentCol]);//add new room
Constants.wallsRef = ROOMS[currentRow][currentCol];//add colision
player.x = 600;
stage.addChild(arrowCount);
stage.addChild(arrowImage);
moved = true;
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
//RIGHT
if(Constants.blockerRef4.hitTestPoint(player.x,player.y) && moved != true){
//this will be where i want to change rooms
stage.removeChild(ROOMS[currentRow][currentCol]);
currentCol++;
Constants.wallsRef = ROOMS[currentRow][currentCol];
stage.addChild(ROOMS[currentRow][currentCol]);
player.x = 10;//change to 600
moved = true;
trace("changed rooms");
stage.addChild(arrowCount);
stage.addChild(arrowImage);
}else if(Constants.playerRef.hitTestObject(Constants.blockerRef1) == false && moved == true){
moved = false;
}
}
function createRooms(){
for(var r = 0; r <ROOMS.length; r++){
walls = new Walls();
addRandomBlocks();
for(var c = 0; c < ROOMS[r].length; c++){
walls = new Walls();
addRandomBlocks();
ROOMS[r][c] = walls;
}
trace(ROOMS[r][c]);
}
}
// [room2, NaN],
// [room6, room1, room5], /// THIS IS THE MAP OF THE FLOOR /// GOING UP ON THE GAME IS GOING DOWN ON IT
// [room7, room8],
// [room3, room9],
// [room4]);
function closeUnnecessaryExits(){
trace("ROW: " + currentRow + " COL: " + currentCol);
var up = ROOMS[currentRow + 1];
var down = ROOMS[currentRow - 1];
var right = ROOMS[currentRow][currentCol + 1];
var left = ROOMS[currentRow][currentCol - 1];
//check to see which outside wasall to use
if(ROOMS[currentRow + 1] == null && up && right && left){
ROOMS[currentRow][currentCol].gotoAndStop(2);
}else if(down == null && left == null && right && up){
ROOMS[currentRow][currentCol].gotoAndStop(3);
}else if(down == null && left == null && up == null && right){
ROOMS[currentRow][currentCol].gotoAndStop(4);
}else if(left == null && down && right && up){// IF HAVING PROBLEMS THEN MAKE THIS MAKE SURE ALL OTHER SIDES ARE TRUE
ROOMS[currentRow][currentCol].gotoAndStop(5);
}else if(down == null && left == null && right == null && up){
ROOMS[currentRow][currentCol].gotoAndStop(6);
}else if(down && up == null && right == null && left == null){
ROOMS[currentRow][currentCol].gotoAndStop(7);
}else if(ROOMS[currentRow + 1][currentCol] == null && ROOMS[currentRow - 1][currentCol] && left && right){
ROOMS[currentRow][currentCol].gotoAndStop(8);
trace("works 1");
}else if(left && right && ROOMS[currentRow - 1][currentCol] == null && ROOMS[currentRow + 1][currentCol] == null){
ROOMS[currentRow][currentCol].gotoAndStop(9);
trace("works 2");
}else if(left && ROOMS[currentRow - 1][currentCol] && right == null && ROOMS[currentRow + 1][currentCol] == null){
ROOMS[currentRow][currentCol].gotoAndStop(10);// LEFT DOWN
trace("works 3");
}else if(left && ROOMS[currentRow + 1][currentCol] && ROOMS[currentRow - 1][currentCol] == null && right == null){
ROOMS[currentRow][currentCol].gotoAndStop(11);//BROKEN left up
trace("working 4");
}else if(left && ROOMS[currentRow + 1][currentCol] == null && ROOMS[currentRow - 1][currentCol] == null && right == null){
ROOMS[currentRow][currentCol].gotoAndStop(12);
trace("works 5");
}else if(right == null && left && up && down){
ROOMS[currentRow][currentCol].gotoAndStop(13);
trace("works 6");
}
}
function addRandomBlocks(){
for(var e=0; e <Math.random() * 10; e++){
//trace("started block");
box = new Box();
box.x = Math.random() * (615 - 100) + 100;
box.y = Math.random() * (500 - 120) + 120;
//colision for block to block
for(var col = 0; col < boxes.length; col++){
if(box.hitTestObject(boxes[col])){
onTop = false;/// THIS NEEDS TO BE TRUE FOR THE DETECTION TO WORK
//trace("THIS BOX IS ON TOP OF ANOTHER");
}
}
if(onTop == false){
boxes.push(box);
walls.addChild(box);
trace("BOX CREATED " + onTop);
//trace(boxes);
}
}
}
}
}
You could streamline your code by creating some simple functions that deal with assigning and accessing values in your 2D array. One that checks if an element within a 2D array exists might look like:
function cellExists(array:Array, x:int, y:int):Boolean {
return array[y] !== undefined && array[y][x] !== undefined;
}
Used like, in your example:
if (cellExists(ROOMS, currentCol, currentRow)) {
//
}
Although with this type of task you would benefit greatly from implementing a class that handles grid + cell data, something along the lines of this to get you started:
public class Grid {
private var _content:Vector.<Vector.<Cell>>;
public function Grid(columns:int, rows:int) {
// Fill _content with empty slots based on columns, rows.
}
public function getCell(x:int, y:int):Cell {}
public function cellExists(x:int, y:int):Boolean {}
}

How to infinite loop numbers in while loops? (Unity3D- unityscript)

function OnMouseDown () {
rotationNumber +=1;
}
function Update () {
while (rotationNumber == 1) {
gameObject.GetComponent(SpriteRenderer).sprite = leftArrow;
return;
}
while (rotationNumber == 2) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
return;
}
while (rotationNumber == 3) {
gameObject.GetComponent(SpriteRenderer).sprite = rightArrow;
return;
}
while (rotationNumber == 4) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
rotationNumber = 1;
return;
}
}
I want to loop this but when I click it the fourth time it just goes straight to the first image. I tried yield WaitForSeconds but it didn't work.
The problem is that you are setting rotationNumber to 1 inside the while loop. Do it in this way:
function OnMouseDown () {
rotationNumber += 1;
if ( rotationNumber > 4 ) rotationNumber = 1;
}
function Update () {
while (rotationNumber == 1) {
gameObject.GetComponent(SpriteRenderer).sprite = leftArrow;
return;
}
while (rotationNumber == 2) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
return;
}
while (rotationNumber == 3) {
gameObject.GetComponent(SpriteRenderer).sprite = rightArrow;
return;
}
while (rotationNumber == 4) {
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
return;
}
}
I'm not quite sure why you are using a while loop within in an update loop, but try this below. Every time you click the rotation number increases and the sprite is changed until the rotationNumber variable is > 4 in which case it resets the variable back to 1.
function Update()
{
if(rotationNumber == 1)
{
gameObject.GetComponent(SpriteRenderer).sprite = leftArrow;
}else if(rotationNumber ==2)
{
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
}else if(rotationNumber ==3)
{
gameObject.GetComponent(SpriteRenderer).sprite = rightArrow;
}else if(rotationNumber == 4)
{
gameObject.GetComponent(SpriteRenderer).sprite = upArrow;
}else if(rotationNumber > 4)
{
rotationNumber = 1;
}
}

Resources