Youtube Video
Download
Click Download to download the game from drive
Here are the scripts that i used in this game. feel free to use those
For highscore counter:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class highscorecounter : MonoBehaviour {
[SerializeField] Text highscore;
void Update()
{
float highscore_count = PlayerPrefs.GetFloat ("Highscore");
highscore.text = highscore_count.ToString ();
}
}
For menumanager :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class menumanager : MonoBehaviour {
public void Startgame()
{
SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);
}
public void Endgame()
{
Application.Quit ();
}
}
For destroying the object after moving down the screen:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ongroundtouchdeath : MonoBehaviour {
void OntriggerEnter2D(Collider2D obj)
{
if (obj.gameObject.tag == "death") {
Destroy (obj.gameObject);
}
else if (obj.gameObject.tag == "sun") {
Destroy(obj.gameObject);
}
}
}
For the game pause :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pausethegamescript : MonoBehaviour {
[SerializeField] GameObject pausemenu;
[SerializeField] GameObject resumegame;
public void gamepause()
{
Time.timeScale = 0;
pausemenu.SetActive(true);
resumegame.SetActive(false);
}
public void gameresume()
{
Time.timeScale = 1;
resumegame.SetActive(true);
pausemenu.SetActive(false);
}
public void timegone()
{
Time.timeScale = 1;
}
}
For the player movement and UI management
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class playermovementscript : MonoBehaviour {
[SerializeField] Text Sunscore;
float scorecounter=0;
[SerializeField] Rigidbody2D player;
[SerializeField] GameObject restartmenu;
void FixedUpdate()
{
Time.timeScale = 1;
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch (0);
Vector3 touch_pos = Camera.main.ScreenToWorldPoint (touch.position);
if (touch_pos.x > 0) {
player.AddForce (new Vector2 (0.25f, 0), ForceMode2D.Impulse);
}
if (touch_pos.x < 0)
{
player.AddForce(new Vector2(-0.25f,0),ForceMode2D.Impulse);
}
}
}
void OnTriggerEnter2D(Collider2D obj) // tick on istrigger in the prefabs of the object that you are spwanning
{
if (obj.gameObject.tag == "death") {
restart ();
}
if (obj.gameObject.tag == "sun") {
scorecounter++;
Destroy (obj.gameObject);
Counter ();
}
}
void restart()
{
restartmenu.SetActive (true);
}
void Counter()
{
float previousscore = PlayerPrefs.GetFloat ("Highscore");
if (previousscore < scorecounter) {
PlayerPrefs.SetFloat ("Highscore", scorecounter);
}
Sunscore.text = scorecounter.ToString ();
}
}
For spanning objects :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spwannerhandler : MonoBehaviour {
[SerializeField] Rigidbody2D spwanningitem;
private float counter = 0;
void FixedUpdate()
{
counter += Time.deltaTime;
if (counter > 3) {
spwan ();
counter = 0;
}
}
void spwan()
{
Instantiate (spwanningitem, new Vector2 (Random.Range (-3f,3f), transform.position.y), Quaternion.identity);
}
}
Make sure the class name matches and the Scripts are assign to the required gameobject.
Thank You
nice game
ReplyDelete