How to Make a Basic Slender AI in Unity (Unity C# Tutorial)

preview_player
Показать описание
In this Unity C# tutorial, I teach you guys how to make a basic Slender AI for your games. If you're looking to make something more advanced, this tutorial may be a good foundation for you to get started.

#Unity #Unity3D #gamedev

*Scripts will be in pinned comment.*

For more Unity tutorials like this or more videos in general - be sure to like, comment, and subscribe for more! 👍

Play Mooshie's Kitchen now:

Wishlist Bodhi 'n' Friends on Steam now:

Use Mixamo for rigging your models if you don't know how to:

Follow me on Twitter:

Try out my games:

My Website:

Subscribe to my Second Channel:

Join my Discord:

Facebook Page:
Рекомендации по теме
Комментарии
Автор

In part 5 of the Slender-like horror game Unity tutorial series, I'll be implementing the scripts I made in this video into that tutorial project when I make the next part. Make sure you watch the tutorial before using these scripts, otherwise you might do something wrong:

slenderAI script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class slenderAI : MonoBehaviour
{
public Transform dest1, dest2, dest3, dest4, dest5, dest6, dest7, dest8, player;
bool teleporting = true;
public float teleportRate;
int randNum;

void Start()
{
StartCoroutine(teleport());
}
void Update()
{
this.transform.LookAt(new Vector3(player.position.x, this.transform.position.y, player.position.z));
}
IEnumerator teleport()
{
while(teleporting == true)
{
yield return new
randNum = Random.Range(0, 8);
if(randNum == 0)
{
this.transform.position = dest1.position;
}
if (randNum == 1)
{
this.transform.position = dest2.position;
}
if (randNum == 2)
{
this.transform.position = dest3.position;
}
if (randNum == 3)
{
this.transform.position = dest4.position;
}
if (randNum == 4)
{
this.transform.position = dest5.position;
}
if (randNum == 5)
{
this.transform.position = dest6.position;
}
if (randNum == 6)
{
this.transform.position = dest7.position;
}
if (randNum == 7)
{
this.transform.position = dest8.position;
}
}
}
}

lookAtSlender script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class lookAtSlender : MonoBehaviour
{
public RawImage staticImage;
public Color color;
public float drainRate, rechargeRate, health, healthDamage, healthRechargeRate, maxStaticAmount;
public float audioIncreaseRate, audioDecreaseRate;
public bool looking, canRecharge;
public AudioSource staticSound;
public string deathScene;

void Start()
{
color.a = 0f;
health = 100f;
}
void OnBecameVisible()
{
looking = true;
}
void OnBecameInvisible()
{
looking = false;
}
void FixedUpdate()
{
if(color.a > maxStaticAmount)
{

}
else if(color.a < maxStaticAmount)
{
staticImage.color = color;
}
if (looking == true)
{
color.a = color.a + drainRate * Time.deltaTime;
health = health - healthDamage * Time.deltaTime;
staticSound.volume = staticSound.volume + audioIncreaseRate * Time.deltaTime;
}
if (looking == false)
{
color.a = color.a - rechargeRate * Time.deltaTime;
if (canRecharge == true)
{
health = health + healthRechargeRate * Time.deltaTime;
}
staticSound.volume = staticSound.volume - audioDecreaseRate * Time.deltaTime;
}
if(health < 1)
{

}
}
}

Omogonix
Автор

This tutorial looks like a great way to get started with making a Slender AI in Unity! Thanks for the helpful tips and resources!

LifeCodeGame
Автор

Nicely implemented. I can see a lot of use cases for this type of mechanic. I appreciate your work on this. Thanks, I've learned a lot here.

jeffreyjumisko
Автор

I love theese tutorials, mostly the sort and random ones. Thank you!

kubzcz
Автор

heads up to anyone who watches this, the scene view counts as a camera, which is stupid but it will make it so that the object/enemy is always in view even if it isn't meant to be. It took me an hour or so of searching he internet to figure out why is looking was always set to true, even when my player was looking the opposite direction, but that's why. might help some people

rhysdavis
Автор

This works awesome!!!
this helped so much!!!

nickname
Автор

Thank you you don't know how much this means to me.

ZanderFam
Автор

Request: a tutorial on a "3am at the krusty krab" style level. That would be heat

EverybodyCartoons
Автор

it works Perfectly only in the Static Script the Video doesent Play Instantly it only does that for the first time.

dimolade
Автор

Hello, The lookAt happens even through walls, is there a way to fix this? I dont want to get jumpscared and killed through the game walls, thank you

omegigaintel
Автор

I hope you show how to make it like the original slender where he disappears after you finish collecting the notes for a short while before spawning again. Or a way to spawn an escape object once all notes are collected.

callofduty
Автор

i try to add the image but its not working

BananaCheese-yw
Автор

hey bro, can you please do a tutorial on how to make the ending scene

BazzyNet
Автор

Yoo! Can you make a tutorial about door opening by grabbing a key and unlock it?

CristianTN
Автор

And with that think that slender man cannot teleport even if you are looking at him trough wall, I think that if you would use raycasts it would fix that right?

kubzcz
Автор

Hey, I'm looking to learn programming in unity and I wanted to know how you learned to do so and where should I learn?

bzyzzzzzzzz
Автор

Didnt this dude created mooshies kitchen?

Skateboard
welcome to shbcf.ru