Evening folks
So fairly new to Unity & C#.
I want my character to bang into an enemy, enemy dies but leaves a puff of feathers in its wake.
So far I have
Created 5 Materials
Assigned different Sprite to each material.
There is a GameObject set as a Prefab with a Particle System attached to it.
A List has been created in C# and all materials assigned to it via the inspector.
A script that calls the Prefab.
Please ignore comments, its just my way of trying and keeping track
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScript : MonoBehaviour
{
private GameObject enemyBird;
private Rigidbody2D bird;
public float horizontalSpeed;
private bool hitPlayer;
private bool hitLightening;
private Animator anim;
private Collider2D coll;
public Vector2 BirdParticleSpawn;
public GameObject ParticleSystemPrefab;
public List<Material> feathermatherial;
public Material newmaterial;
private void Start()
{
coll = GetComponent<Collider2D>();
anim = GetComponent<Animator>();
enemyBird = GetComponent<GameObject>();
bird = GetComponent<Rigidbody2D>();
bird.velocity = new Vector2(Random.Range(-6, -12), 0);
Object.Destroy(this.gameObject, 7);
}
private void Update()
{
if (hitPlayer)
{
bird.velocity = new Vector2(Random.Range(4, 8), (Random.Range(-10, -16)));
Object.Destroy(this.gameObject, 6);
}
else if (hitLightening)
{
bird.velocity = new Vector2(0, -1);
Object.Destroy(this.gameObject, 1);
}
else if (PlayerScoreManager.Instance.Meters > GameManager.Instance.level3Text + 40 && PlayerScoreManager.Instance.Meters < GameManager.Instance.level4Text + 40)
{
bird.velocity = new Vector2(Random.Range(-5, -8), 0);
Object.Destroy(this.gameObject, 7);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
hitPlayer = true;
PlayerInput.rb.velocity = new Vector2(-4, -1);
PlayerHealthManager.Instance.SubtractFart(10);
anim.SetBool("BirdHitPlayer", true);
ParticleSpawn();
}
if (collision.gameObject.tag == "FartShot")
{
PlayerScoreManager.Instance.AddBird(1);
hitPlayer = true;
anim.SetBool("BirdShot", true);
PlayerScoreManager.Instance.AddScore(20);
}
if (collision.gameObject.tag == "birddunk")
{
PlayerScoreManager.Instance.AddBird(1);
PlayerScoreManager.Instance.AddScore(100);
Dunked.ifDunked = true;
BirdSlamDunkSpawn.playDunkedAnimation = true;
Object.Destroy(this.gameObject, 0);
}
if (collision.gameObject.tag == "lightening")
{
anim.SetBool("BirdShocked", true);
hitLightening = true;
coll.enabled = false;
}
if (collision.gameObject.name == "lighteningBall")
{
anim.SetBool("BirdShocked", true);
hitLightening = true;
coll.enabled = false;
}
}
public void ParticleSpawn()
{
//Get Current Bird Location and place in BirdXY
float BirdX = GetComponent<Transform>().position.x;
float BirdY = GetComponent<Transform>().position.y;
// foreach (var item in feathermatherial)
// {
// ParticleSystemPrefab.GetComponentInChildren<Material>();
// }
//newmaterial = Random.Equals(feathermatherial);
//ParticleSystemPrefab.GetComponentInChildren<Material>().
//Load Prefab on BirdXY location
Instantiate(ParticleSystemPrefab, new Vector2(BirdX,BirdY), Quaternion.identity);
//Play Prefab
ParticleSystemPrefab.GetComponent<ParticleSystem>().Play();
}
}
Any help appreciated
Regards
N