1st Game Using Unity :)

Karuna Ketan
1 min readDec 6, 2022

1st Game using Unity :)

Hope you will love it…

Download it from here -

Drive Link — https://drive.google.com/drive/folders/1vFFFuQf2weJYG941v4b429ff7kDzDkxg?usp=sharing

Github Link — https://github.com/karunaket/1st-Game-With-Unity

Watch Video Here — https://vimeo.com/778566957

Today I made a Game using Unity…

PlayerController code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Rigidbody2D _rb;
[SerializeField] ObjectBehaviour _objectBehaviour;

float _playerSpeed = 10f;
float _inputHorizontal;

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

_rb = gameObject.GetComponent<Rigidbody2D>();

_objectBehaviour.SpawnObject();
}

// Update is called once per frame
void Update()
{
_inputHorizontal = Input.GetAxisRaw("Horizontal");

if (_inputHorizontal != 0)
{
_rb.AddForce(new Vector2(_inputHorizontal * _playerSpeed, 0));
}
}
}

ObjectBehaviour code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectBehaviour : MonoBehaviour
{
[SerializeField] GameObject _prefab;
bool _gameOver = false;

public void SpawnObject()
{
Instantiate(_prefab, new Vector3(Random.Range(-8f, 8f), 9.48f, 0f), Quaternion.identity);
}

private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Player" && !_gameOver)
{
SpawnObject();
Destroy(gameObject);
}
else if (collision.gameObject.tag == "Ground")
{
_gameOver = true;
Debug.Log("GAME OVER! YOU LOOSE!");
}
}
}

click here to follow me in LinkedIn for more updates…

click here to follow me in GitHub for more updates…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Karuna Ketan
Karuna Ketan

Written by Karuna Ketan

Game Designer and Developer | Unity, Unreal Engine, Blender

No responses yet

Write a response