using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class aircraftGun : MonoBehaviour
{
public GameObject[ ] firepoint;
public ParticleSystem[ ] shootingParticle;
public AudioSource[ ] shootingSound;
public RaycastHit rayHit;
public int damage;
public LayerMask whatIsEnemy;
public int range;
// Update is called once per frame
void Update()
{
Vector3 direction = firepoint.transform.forward;
if (Physics.Raycast(firepoint.transform.position, direction, out rayHit, range, whatIsEnemy))
{
Debug.Log(rayHit.collider.name);
}
shootingParticle.Play;
shootingSound.Play;
}
}
Please use Code Tags when sharing code on the forums for easier readability.
firepoint, shootingParticle, and shootingSound are all declared as arrays in your class, but you seem to be treating them as individual objects. That’s your problem. Either make them individual objects or deal with them as arrays.
thanks ,so how do i treat them as arrays?
It really depends what you want to do with them? You could do something with individual elements of the arrays, which maybe makes sense if it represents a “currently equipped” weapon or something. Or you could loop through and do something with all the elements of the array…
What are you trying to accomplish with this code?
i got airplane script from unity standard assets, so now im trying to make a fighter plane that can shoot.