1. How does one declare a class variable in C#?
2. Write a C# script for a game object to call the function foo(), every 10 seconds after the game starts.
3. Write a c# fragement to change an object's texture, when the is store in the variable objectvariable and the texture is stored in the variable mytexture.
Design:
CodeSnap:
Coding
game.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleClassExample
{
class game//create new class
{
string mytexture;//declare instant variable here
public string foo()//make function for display instant
variable
{
return this.mytexture;
}
public void changeTexture(String s)//change instant variable text
from here
{
this.mytexture = s; //change texture from here
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimpleClassExample
{
public partial class Form1 : Form
{
game g1 = new game();//declare new object of game
int i = 0;//declare variable here
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();//timer will start from load time
}
private void timer1_Tick(object sender, EventArgs e)
{
g1.changeTexture("My texture is :"+Convert.ToString((i)));//change
texture from here
label1.Text=g1.foo();//display it
i++;
}
}
}
output:
if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........
Get Answers For Free
Most questions answered within 1 hours.