Day 136 — Creating Blood Splat Effects

[SerializeField]
private GameObject _bloodSplat;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 center = new Vector3(0.5f, 0.5f, 0);
Ray rayOrigin = Camera.main.ViewportPointToRay(center);
RaycastHit hitInfo;
if (Physics.Raycast(rayOrigin, out hitInfo))
{
Debug.Log("Hit: " + hitInfo.collider.name);
Health health = hitInfo.collider.GetComponent<Health>();
if (health != null)
{
Instantiate(_bloodSplat, hitInfo.point, Quaternion.LookRotation(hitInfo.normal));
health.Damage(50);
}
}
}
public void StartAttack()
{
_currentState = EnemyState.Attack;
}
public void StopAttack()
{
_currentState = EnemyState.Chase;
}
private EnemyAI _enemyAi;void Start()
{
_enemyAi = GetComponentInParent<EnemyAI>();
if (_enemyAi == null)
{
Debug.LogError("The enemy AI is null");
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
_enemyAi.StartAttack();
}
}
private void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
_enemyAi.StopAttack();
}
}
[SerializeField]
private GameObject _bloodSplat;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 center = new Vector3(0.5f, 0.5f, 0);
Ray rayOrigin = Camera.main.ViewportPointToRay(center);
RaycastHit hitInfo;
if (Physics.Raycast(rayOrigin, out hitInfo, Mathf.Infinity, 1 << 7))
{
Debug.Log("Hit: " + hitInfo.collider.name);
Health health = hitInfo.collider.GetComponent<Health>();
if (health != null)
{
Instantiate(_bloodSplat, hitInfo.point, Quaternion.LookRotation(hitInfo.normal));
health.Damage(50);
}
}
}

--

--

--

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Mizar journey to the Big Dipper

📝Case Study on Amazon SQS(A message queuing service)

Right way of asserting a proper state of an iOS app.

Native Android & iOS Firebase Notifications (Google Cloud Messaging) — Product Owner Cheatsheet

How to clone a hard drive using docking station?

Android Trends in 2020

Unity2D Devlog 19 — Beating Them To It

#freestockphoto (Tuesday 24th 02PM)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Connor Fullarton

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

More from Medium

Unity TileMap: Smooth Movement in a Top-Down Game

Unity’s Tilemap System

Creating Fog and Using Particles in Unity3D and the URP

3rd Person Follow Virtual Camera Explained in Unity’s Cinemachine