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

Sitespeed.io Web UI — for starters

Sitespeed.io Web Interface

Instance Dashboard Using S3, Lambda and API Gateway

Make your own Operating System#6

4 Popular Tools For Agile Project Management | Bridge Blog

Insights from MyMDT Closed Beta Testing

Tech Dream in Reverse

LeetCode 1103. Distribute Candies to People

Nu World fishing area is being prepared!

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

Enabling Unity Ads

Week 24: How to add SFX to you game without going mad

IWTV is part of Indy Pro ‘22

My journey becoming a Unity game developer: 2.5D Infinite Runner-Ledge Grab System-Pt3