Story of 3D 5 vs 5 team Game by using Photon.Pun On Unity engine(For mobile)
(this is not a guide for building a Mobo game on photon server its just story of how we create)
Our main target is to create our own 5 vs 5 multiplayer game this project as you see on header.
For the beginning we are decided to do:
- Different guns for each player.
- Different Characters
- Identical skills and and values (Health,speed and jump length etc.)
- Display Skills Characters sprite
- Display Gun sprite,username.
- ZERO Asset from unity store
First we start with out Photon
Using Scriptable object to make gunsStad:
Creating scriptable objects gives great advantages for future changes on game. So i create a my first Scriptable Object named GunsStad
so i add new folder named Gun in Assets folder and add GunsStad script just like this:
Yes there are only some values its easy and very useful. I will use this variables to my all guns. Now at the top Unity Scene When I click expand Asset =>Create=> right there i can see my Guns are waiting me to click for create new gun. Isn't it awesome?
And right now when click it Unity will create a New Gun in a folder I choose. I just going to change the name of it as I wish. I this case I write "Pistol".In the Ispector will appear pistol values that i have to fill and just like this:
I can make another gun named Shot gun;
How easy isn't it :) And size of it very small. So We already made stats of guns. Lets create First gun
Function. I will Write a new script named "Shoot" this will be same for all guns.Just variables will give this differentiates to guns:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Shoot : MonoBehaviour
{
public GunsStat _gunStat;
public GameObject bullet;
public float reloadTime;
public int bulletCapacity;
public Transform[] ShotPos;
private int Clicked;
public Text bulletText;
// Start is called before the first frame update
void Start()
{
bulletCapacity = _gunStat.capacity;
reloadTime= _gunStat.reloadTime;
Clicked = bulletCapacity;
bulletText.text = bulletCapacity.ToString();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (Clicked > 0)
{
Fire();
Clicked--;
bulletCapacity -= 1;
bulletText.text = bulletCapacity.ToString();
if (Clicked <= 0)
{
bulletText.text = "Reloading";
StartCoroutine(Reload());
}
}
}
}
void Fire()
{
GameObject _bullet = Instantiate(bullet, ShotPos[0].transform.position, ShotPos[0].transform.transform.rotation);
Rigidbody _bullet_rb = _bullet.GetComponent<Rigidbody>();
_bullet_rb.AddForce(10000 * Time.deltaTime, ShotPos[0].transform.forward,ForceMode.Impulse);
}
IEnumerator Reload()
{
yield return new WaitForSeconds(reloadTime);
bulletCapacity = _gunStat.capacity;
bulletText.text = bulletCapacity.ToString();
Clicked = bulletCapacity;
}
}
As you see to use scriptable objects variables we are implementing the all variables to this Gun(Pistol)
And In update function I am calculating clips capacity of gun. Coroutine is using Reload time to reload bullets.