Info part 4:
1. Create Player
- Moment
- Gun Fire, switch Gun1, Gun2, ...
- Bullet is one style gun
- Change color Player is fire damge
....***
Structure Player Object
Player
+ Gun
+ StartBullet (point bullet start)
+ Shield (State )
+ PlayerLine (line foot player)
Code:
LineRenderer Linerend;
public Transform lazehit;
void Start () {
Linerend = this.GetComponent<LineRenderer>();
Linerend.useWorldSpace = true;
}
// Update is called once per frame
void Update () {
Linerend.SetPosition(0, transform.position);
Linerend.SetPosition(1, lazehit.position);
Linerend.SetWidth(0.1F, 0.1F);
}
******************
Code :
++ PlayerMovement
<script>
public void setVector(int i)
{
if (i == 1)
{
//right
right = true;
left = false;
up = false;
down = false;
}
else if (i == -1)
{
//left
left = true;
right = false;
up = false;
down = false;
}
else if (i == 2)
{
//up
up = true;
down = false;
right = false;
left = false;
}
else if (i == -2)
{
//down
down = true;
up = false;
right = false;
left = false;
}
else
{
right = false;
left = false;
up = false;
down = false;
}
}
if (_state != StatePlayer.IsLockMoment && _state != StatePlayer.IsStart)
{
var velX = speed;
var velY = speed;
if (right || left)
{
velX *= left ? -1 : 1;
velY = 0;
}
else
{
velX = 0;
}
if (up || down)
{
velY *= down ? -1 : 1;
velX = 0;
}
else
{
velY = 0;
}
body2d.velocity = new Vector2(velX, velY);
}
else
{
body2d.velocity = new Vector2(0,0);
}
++ Gun :
Change Gun:
IEnumerator SpriteGenerator()
{
if (FireActive)
{
ResetSpriteGun();
for (int i = 0; i < Gunsprite.Length; i++)
{
yield return new WaitForSeconds(delaySprite);
this.GetComponent<SpriteRenderer>().sprite = Gunsprite[i];
}
}
}
void ResetSpriteGun()
{
if (IDgunActiveLast != IDGunActive)
{
IDgunActiveLast = IDGunActive;
for (int i = 0; i < GunStyles.Length; i++)
{
if (GunStyles[i].ID == IDGunActive)
{
Gunsprite = GunStyles[i].Gunsprite;//set style
IDBullet = GunStyles[i].IDBullet;
}
}
//
CurrentBullet = Bullets[IDGunActive - 1];
Speedbullet = CurrentBullet.GetComponent<Bullet>().shootSpeed;
if(PlayerPrefs.GetInt("ChangedelayGun")==0)
delayGun=CurrentBullet.GetComponent<Bullet>().delayGun;
}
}
++ Bullet
var newTransform = StartBullet;
StartCoroutine(SpriteGenerator());
//set paramter is Bullet
if (CurentSpeedbullet != Speedbullet)
{
CurentSpeedbullet = Speedbullet;
CurrentBullet.GetComponent<Bullet>().shootSpeed = Speedbullet;
}
//intance bullet
//Audio
gmctr.PlayClipShort(12);
gmctr.PlayClipShort(11);
if(IDGunActive!=6&& IDGunActive!=4)
GameObjectUtil.Instantiate(CurrentBullet, newTransform.position);
if (IDGunActive == 4)
{
// 2 bullet
Quaternion ro1 = Quaternion.Euler(new Vector3(0, 0, -6));
Quaternion ro3 = Quaternion.Euler(new Vector3(0, 0, 6));
GameObjectUtil.Instantiate(CurrentBullet, newTransform.position, ro1);
GameObjectUtil.Instantiate(CurrentBullet, newTransform.position, ro3);
}
if (IDGunActive == 6)
{
// 3 bullet
Quaternion ro1 = Quaternion.Euler(new Vector3(0, 0,-12));
Quaternion ro2 = Quaternion.Euler(new Vector3(0, 0, 0));
Quaternion ro3 = Quaternion.Euler(new Vector3(0, 0, 12));
GameObjectUtil.Instantiate(CurrentBullet, newTransform.position, ro1);
GameObjectUtil.Instantiate(CurrentBullet, newTransform.position, ro2);
GameObjectUtil.Instantiate(CurrentBullet, newTransform.position, ro3);
}
++ Player Line
// Use this for initialization
LineRenderer Linerend;
public Transform lazehit;
void Start () {
Linerend = this.GetComponent<LineRenderer>();
//Linerend.enabled = false;
Linerend.useWorldSpace = true;
}
// Update is called once per frame
void Update () {
// RaycastHit2D hit2d = Physics2D.Raycast(transform.position, transform.up);
Linerend.SetPosition(0, transform.position);
Linerend.SetPosition(1, lazehit.position);
Linerend.SetWidth(0.1F, 0.1F);
//Linerend.SetWidth(0.01f, 0.01f);
//Debug.DrawLine(transform.position, lazehit.position);
}
----***
Video: Tutorials
***************************
Author:
Xh Studio
Page Google Store:
Store Game
Game First:
Pest Hunter