0% found this document useful (0 votes)
8 views12 pages

CGP Assignment #02

Uploaded by

Farah Ismail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

CGP Assignment #02

Uploaded by

Farah Ismail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

: ASSIGNMENT NO.

2:

: C# SCRIPT FOR A 2D CHARACTER:

NAME: RIDA FATIMA (BSE223046), SYEDA MARYAM ALI(BSE223054)


COURSE TITLE: COMPUTER GAME PROGRAMMING
COURSE CODE: SE-3173
SECTION:01
ASSIGNMENT NO:02
SUBMISSION DATE: 4TH NOVEMBER,2024
INSTRUCTOR NAME: SIR IBRAR ARSHAD
QUESTION:
For the 2D character you imported in Assignment 1, write the following C# scripts to interact
with the it by using following keys.

 Up Arrow – Movement in upword direction


 Down Arrow – Movement downword direction
 Left Arrow – Movement left direction (face of the character should be in left side)
 Right Arrow – Movemnt right direction (face of the character should be in Right side)
 a – Increase the size (twice)
 s – Decrease the size (half)
 h – Move the character to home (assume coordinates of character’s home and move the
character to those coordinates)

SCRIPT:

OUTPUT SCREENSHOT AT DIFFERENT POSITIONS:


CHARACTER AT STATIONARY POSITION:

1. Up Arrow – Movement in upword direction:

SCRIPT:
using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Upward : MonoBehaviour

// Start is called before the first frame update

void Start()

}
// Update is called once per frame

void Update()

if(Input.GetKey(KeyCode.UpArrow))

transform.Translate(Vector2.up *Time.deltaTime *2.5f);

OUTPUT:
2. Down Arrow – Movement downword direction:
SCRIPT:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Downward : MonoBehaviour

// Start is called before the first frame update

void Start()

// Update is called once per frame

void Update()

if(Input.GetKey(KeyCode.DownArrow))

transform.Translate(Vector2.down *Time.deltaTime *2.5f);

}
}

Output:

3. Left Arrow – Movement left direction (face of the character should be in left
side):
SCRIPT:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Leftside: MonoBehaviour

// Start is called before the first frame update

void Start()

// Update is called once per frame

void Update()

{
if(Input.GetKey(KeyCode.LeftArrow))

transform.localScale=new Vector2(-3,3);

transform.Translate(Vector2.left *Time.deltaTime *2.5f);

OUTPUT:

 Face of the character in left side:


4. Right Arrow – Movemnt right direction (face of the character should be in Right
side):
SCRIPT:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Rightside : MonoBehaviour

// Start is called before the first frame update

void Start()

// Update is called once per frame

void Update()

if(Input.GetKey(KeyCode.RightArrow))

transform.localScale=new Vector2(6,6);
transform.Translate(Vector2.right *Time.deltaTime *2.5f);

OUTPUT:

5. a – Increase the size (twice):


SCRIPT:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Increase : MonoBehaviour

// Start is called before the first frame update

void Start()

// Update is called once per frame

void Update()
{

if(Input.GetKey("a"))

transform.localScale=new Vector2(transform.localScale.x*2,transform.localScale.y*2);

OUTPUT:

6. s – Decrease the size (half):


SCRIPT:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Increase : MonoBehaviour

// Start is called before the first frame update

void Start()

{
}

// Update is called once per frame

void Update()

if(Input.GetKey("s"))

transform.localScale=new Vector2(transform.localScale.x/2,transform.localScale.y/2);

}
}

OUTPUT:

7. h – Move the character to home (assume coordinates of character’s home and


move the character to those coordinates):
SCRIPT:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;
public class Move : MonoBehaviour

// Start is called before the first frame update

void Start()

// Update is called once per frame

void Update()

{
if(Input.GetKey("h"))

transform.position=new Vector2(0,0);

OUTPUT:

You might also like