hi i need help i am trying to create a code for a bullet decal but it doesn’t work how to do it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class decal : MonoBehaviour
{
public Transform Barrel;
public GameObject[] DecalHoleC;
public GameObject EffectC;
public GameObject[] DecalHoleM;
public GameObject EffectM;
public GameObject[] DecalHoleW;
public GameObject EffectW;
public Camera Camera;
// Start is called before the first frame update
// Update is called once per frame
public void Shoot()
{
Ray rayorigin = Camera.ScreenPointToRay(new Vector2(Screen.height / 2, Screen.width / 2));
RaycastHit hitinfo;
if(Physics.Raycast(rayorigin, out hitinfo))
{
if(hitinfo.collider.tag == "Concrete")
{
GameObject bulletUse1 = DecalHoleC[Random.Range(0,DecalHoleC.Length)];
Instantiate(EffectC);
Instantiate(DecalHoleC[Random.Range(0, DecalHoleC.Length)], hitinfo.point, Quaternion.LookRotation(hitinfo.normal));
Vector3 direction = hitinfo.point - Barrel.position;
Barrel.rotation = Quaternion.LookRotation(direction);
}
if(hitinfo.collider.tag == "Metal")
{
GameObject bulletUse2 = DecalHoleM[Random.Range(0,DecalHoleM.Length)];
Instantiate(EffectM);
Instantiate(DecalHoleM[Random.Range(0, DecalHoleM.Length)], hitinfo.point, Quaternion.LookRotation(hitinfo.normal));
Vector3 direction = hitinfo.point - Barrel.position;
Barrel.rotation = Quaternion.LookRotation(direction);
}
if(hitinfo.collider.tag == "Wood")
{
GameObject bulletUse3 = DecalHoleW[Random.Range(0,DecalHoleW.Length)];
Instantiate(EffectW);
Instantiate(DecalHoleW[Random.Range(0, DecalHoleW.Length)], hitinfo.point, Quaternion.LookRotation(hitinfo.normal));
Vector3 direction = hitinfo.point - Barrel.position;
Barrel.rotation = Quaternion.LookRotation(direction);
}
}
}
}