AI and player guns not fireing, have i missed a step here? error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Hi gang, just tested my game everything is set up and YES everything has ridgid bodies and triggers and tags have been set however my guns fail to fire.
have a box extruding out from the AI-bot and set to trigger as player enters this triggerbox it acts as aline of sight and sets fireing to true sdo the bot can fire at the player. error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
using UnityEngine;
using System.Collections;
public class ET_AI_ : MonoBehaviour {
// OUT THIS SCRIPT ONAI ET FIGHTER HITBOX.
//guns:
public GameObject Gunslocation;
public GameObject bulletPrefab;
public AudioClip GunsETFighter;
public int IsShooting = 0;
public int GunsFireing = 1;
public int Gunsoff = 0;
public int firerate = 12;
public int burstrate = 5;
// If Player Enters Trigger:
//---------------------------------------------------------------------------------------------------------------------
void OnTriggerEnter(Collider Collider)
{
if(GetComponent<Collider>().tag == "Player")
{
IsShooting == GunsFireing;
}
} // End triggger
//---------------------------------------------------------------------------------------------------------------------
void OnTriggerExit(Collider collider2)
{
if(collider2.tag == "Player")
{
IsShooting == Gunsoff;
}
} // End triggger
//---------------------------------------------------------------------------------------------------------------------
// if can shoot fire guns.
void Update()
{
if (IsShooting > 0) {
if(IsShooting > 0) StartCoroutine(FireBurst(bulletPrefab,1,10)); }
}
//---------------------------------------------------------------------------------------------------------------------
IEnumerator FireBurst(GameObject bulletPrefab, int burstSize, float rateOfFire)
{
float bulletDelay = 60 / rateOfFire;
// rate of fire in weapons is in rounds per minute (RPM), therefore we should calculate how much time passes before firing a new round in the same burst.
for (int i = 0; i < burstSize; i++)
{
Rigidbody clone2;
clone2 = (Rigidbody)Instantiate (bulletPrefab, transform.position, transform.rotation);
yield return new WaitForSeconds(bulletDelay); // wait till the next round
Debug.Log("I Am Fireing");
}
}
}
Answer by Bonfire-Boy · Jan 30, 2016 at 07:00 PM
In brief... lines 24 and 35 you've put ==
where it should be =
This IsShooting == Gunsoff;
is a comparison, but you're not doing anything with it. That's what the error message is complaining about. Presumably you're trying to assign a value, which would be IsShooting = Gunsoff;
I'm confused by your description of the problem, though. "X not firing" sounds like it's running but not working properly. But the error is a compiler error, so I wouldn't expect it to be running at all.
Your answer
Follow this Question
Related Questions
3D Survival Shooter Tutorial Movement Code Errors 0 Answers
ScriptableObjects instances and RAM usage. 0 Answers
input.getaxis not working 2 Answers
Why do i get NullReferenceException here? 1 Answer
HELP ME PLEASE! 1 Answer