How to Create a Simple Dynamic Crosshair (Unity3D, C#, Game Design)

preview_player
Показать описание
Nice quick tutorial on how to make a simple dynamic crosshair for your Unity game using no external assets (for the crosshair). Code is written in C#, and if you can't be fussed with following along and writing out the code, you can get the script below. Use it however you like but please consider leaving a like and maybe subscribing if you find the video or the code helpful. Mwah.

Get the code here;

SOCIAL STUFF!

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

I’ve been trying to learn as much as I can before I attempt to make my first game your tutorials are most definitely helping

Grimzonix
Автор

Developers that are serious about providing tutorials could learn a lot from your format, delivery, and concise information included in the video. This video perfectly embodies what Youtube is meant to achieve. Quick, concise, informative - Cheers!

garrettjarvis
Автор

Hey dude! thanks for this video. I don't speak English very well, but the little I know was enough to understand your entire video(your teaching is very good), which helped me a lot in my project.

gumbo
Автор

I suggest you to use the outliner on the crosshair to make it more visible

luke
Автор

Thanks for this. I was looking everywhere.

elixer_prince
Автор

Exactly what I was looking for. Thanks!

astrodyl
Автор

Great, I Can solve my problem with crosshair in my FPS Creation hahahaha, congratulations, you a got +1 subscriber !!! that helps me a lot

toitoesporte
Автор

That's fun and all, but here's the real challenge, generating random bullets within the radius of the crosshair on screen, radius being the distance from the middle point of the crosshair to one of the endpoints of the crosshair that's closest to the middle point, ASSUMING that all crosshairs distance from the middle point are equivalent.

zoop
Автор

i did everything exactly but my top and bottom corssair are invisible ingame

valverdeh
Автор

For me it does not change the blue dot when i change pivot, why is that?

eriknilsson
Автор

If u jump it doesn’t work does anyone know how to get it to work if u move along the y axis

l_duke_l
Автор

images that i crate are transparent.. doesnt work..

sylmix-private
Автор

Can you animate crosshairs using Tween? so it's less taxing on the performance for every frame? I've been struggling on finding information on spreading a crosshair to move on player input. trying to move a character controller in VR so when my character walks the crosshair spreads and when he Runs faster it spreads furth but always retracts slowly when going back into an idle state. I noticed when using basic UI canvas to add a crosshair, it does slow performance down because it's drawing every frame an update. if anyone has any clue how to implement this it would help or at least send me somewhere. Trying to just make some old-school 2001 Ghost recon Crosshairs or old-school Rainbow six crosshairs from the n64 days animated in a VR setting.

Mad_Luv
Автор

wow this is really really cool !!! is it also possible to let the crosshair turn red or turn red and change size as aiming at an enemy ??

souhailla
Автор

Hey, I followed all of the instructions in the video, but unity says that Input Axis horizontal is not set up. any idea as to why that might be?
btw, I used the isMoving method, not the rigidbody one

arastoog
Автор

How do I get it to go away when aiming?

AZASeraph
Автор

I dont know why but you sound like someone I have bumped into! LOL

EaglefireflyGaming
Автор

Hey!, I have a question, I want that when the player presses the right button the CrossHair is hidden, and when they release the button it becomes visible. How can I do that?

theanimatronicgamerreturn
Автор

great video but that's not how you use Mathf.Lerp, the parameter t is how much "a" has lerped to "b" in percentage, and therefore Mathf.Lerp should be used in an IEnumerator not Update

joshuamason
Автор

If you people dont to use riged body i make it work with character controler heres a script.


using UnityEngine;

public class DynamicCrosshair : MonoBehaviour
{
public CharacterController characterController;
public RectTransform crosshair; // Reference to the crosshair's RectTransform component
public float maxCrosshairSize = 100f; // Maximum size of the crosshair
public float crosshairSpeed = 5f; // Speed at which the crosshair follows player's velocity

private float initialCrosshairSize; // Initial size of the crosshair

private void Start()
{
initialCrosshairSize = crosshair.sizeDelta.x; // Store the initial size of the crosshair
}

private void Update()
{
// Get the player's velocity
Vector3 velocity =

// Calculate the magnitude of the velocity
float speed = velocity.magnitude;

// Calculate the size of the crosshair based on the player's speed
float crosshairSize = initialCrosshairSize + (speed * crosshairSpeed);

// Clamp the crosshair size within the specified range
crosshairSize = Mathf.Clamp(crosshairSize, 0f, maxCrosshairSize);

// Set the size of the crosshair
crosshair.sizeDelta = new Vector2(crosshairSize, crosshairSize);
}
}

donotprikel