- Home /
Unity 2d game: How to change aim line (line Renderer) dots?
I am working on a small game project for a shooter with aim line and I was able to make this aim line with Line Renderer but I can't change the shape of that line. I wanted something like little round dots. It seems to me that it would have something to do with the Default-particle in the Inspector Tab but how do I change that stuff? Do I create the material and replace it? if so how?
I put here some images of how the aim line are in this moment, how the Inspector Tab are and my code of the Line Renderer. Thanks so much for some help.
The code of the Line Renderer:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(LineRenderer))]
public class Weapon : MonoBehaviour
{
[Range(1, 5)]
[SerializeField] private int _maxIterations = 5;
[SerializeField] private float _maxDistance = 25f;
public int _count;
public LineRenderer _line;
public int ammo;
public Transform Firepoint;
public GameObject BulletPrefab;
public GameObject FirePrefab;
private void Start()
{
_line = GetComponent<LineRenderer>();
}
// Update is called once per frame
private void Update()
{
if (Input.GetButtonDown("Fire1") && ammo > 0)
{
Shoot();
}
_count = 0;
_line.SetVertexCount(1);
_line.SetPosition(0, transform.position);
_line.enabled = true;
RayCast(transform.position, transform.right);
}
private void Shoot()
{
//shooting logic
var destroyBullet = Instantiate(BulletPrefab, Firepoint.position, Firepoint.rotation);
ammo--;
Destroy(destroyBullet, 10f);
var destroyFire = Instantiate(FirePrefab, Firepoint.position, Firepoint.rotation);
Destroy(destroyFire, 0.3f);
}
private bool RayCast(Vector2 position, Vector2 direction)
{
RaycastHit2D hit = Physics2D.Raycast(position, direction, _maxDistance);
if (hit && _count <= _maxIterations - 1)
{
_count++;
var reflectAngle = Vector2.Reflect(direction, hit.normal);
_line.SetVertexCount(_count + 1);
_line.SetPosition(_count, hit.point);
RayCast(hit.point + reflectAngle, reflectAngle);
return true;
}
if (hit == false)
{
_line.SetVertexCount(_count + 2);
_line.SetPosition(_count + 1, position + direction * _maxDistance);
}
return false;
}
}
Your answer
Follow this Question
Related Questions
Having problem with killing aliens in Space Invaders. 2 Answers
Third Person Aiming 0 Answers
Unity 2D -Reflecting a linerenderer 2 Answers
How to Fix "NullReferenceException"? Aim Down Sights Script 1 Answer
Move to line 0 Answers