0% found this document useful (0 votes)
12 views10 pages

Cgprograms

The document outlines a computer graphics project titled 'Harry Potter and Deathly Dementors,' featuring various scripts for game elements. Key components include background music management, obstacle handling, camera movements, looping backgrounds, player controls, and obstacle spawning. Each script is designed to enhance gameplay mechanics in a Unity environment.

Uploaded by

pratiknew03
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)
12 views10 pages

Cgprograms

The document outlines a computer graphics project titled 'Harry Potter and Deathly Dementors,' featuring various scripts for game elements. Key components include background music management, obstacle handling, camera movements, looping backgrounds, player controls, and obstacle spawning. Each script is designed to enhance gameplay mechanics in a Unity environment.

Uploaded by

pratiknew03
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/ 10

CUMPUTER

GRAPHICS
PROJECT
PROJECT NAME – HARRY POTTER AND
DEATHLY
DEMENTORS
Backgroundmusic

using System.Collections.Generic;
using UnityEngine;

public class Backgroundmusic : MonoBehaviour


{
private static Backgroundmusic backgroundMusic;
void Awake()
{
if (backgroundMusic == null)
{
backgroundMusic = this;
DontDestroyOnLoad(backgroundMusic);

}
else
{
Destroy(gameObject);

}
Obstacles

using System.Collections.Generic;
using UnityEngine;

public class Obstacle : MonoBehaviour


{
// Start is called before the first frame update
void Start()
{

}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Border")
{
Destroy(this.gameObject);
}
}

}
Cameramovements

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Cmeramovement : MonoBehaviour


{
public float cameraSpeed;

// Update is called once per frame


void Update()
{
transform.position += new Vector3(cameraSpeed * Time.deltaTime, 0, 0);
}
}
Loopingbackground

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour


{
public float backgroundSpeed;
public Renderer backgroundRenderer;

// Update is called once per frame


void Update()
{
backgroundRenderer.material.mainTextureOffset += new Vector2(backgroundSpeed *
Time.deltaTime, 0f);
}
}
Player.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour

public float playerSpeed;

private Rigidbody2D rb;

private Vector2 playerDirection;

// Start is called before the first frame update

void Start()

{
rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame


void Update()
{

float directionY = Input.GetAxisRaw("Vertical");

playerDirection = new Vector2(0, directionY).normalized;


}

void FixedUpdate()
{
rb.velocity = new Vector2(0, playerDirection.y * playerSpeed);
}
}
Spawnobstacles

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnObstacles : MonoBehaviour


{
public GameObject obstacle;
public float maxX;
public float minX;
public float maxY;
public float minY;
public float timeBetweenSpawn;
private float spawnTime;

// Update is called once per frame


void Update()
{
if (Time.time > spawnTime)
{
Spawm();
spawnTime = Time.time + timeBetweenSpawn;

}
}
void Spawm()
{
float randomX = Random.Range(minX, maxX);
float randomY = Random.Range(minY, maxY);
Instantiate(obstacle, transform.transform.position + new Vector3(randomX, randomY, 0),
transform.rotation);
}
}

You might also like