KlVI
1
I know this has been asked many times before but i couldn’t solve the problem, heres the code (it’s in C#) :
using UnityEngine;
using System.Collections;
public class Inaccurate Firing Script : MonoBehaviour
{
public GameObject Bullet_Emitter;
public GameObject Bullet;
public float Bullet_Forward_Force;
public float accuracy = 0.03f;
void Start ()
{
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
GameObject Temporary_Bullet_Handler;
Temporary_Bullet_Handler = Instantiate(Bullet,Bullet_Emitter.transform.position,Bullet_Emitter.transform.rotation) as GameObject;
Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);
Rigidbody Temporary_RigidBody;
Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent();
.
Temporary_RigidBody.AddForce(transform.right * Bullet_Forward_Force + Vector3
(Random.Range(-accuracy, accuracy)
(Random.Range(-accuracy, accuracy),0.0f ) ) );
Destroy(Temporary_Bullet_Handler, 5.0f);
}
}
}
please use code tags Using code tags properly - Unity Engine - Unity Discussions
Inaccurate Firing Script
Your class name can’t have spaces for one…
1 Like
USE CODE TAGS!
using UnityEngine;
using System.Collections;
public class Inaccurate Firing Script : MonoBehaviour
{
public GameObject Bullet_Emitter;
public GameObject Bullet;
public float Bullet_Forward_Force;
public float accuracy = 0.03f;
void Start ()
{
}
void Update ()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
GameObject Temporary_Bullet_Handler;
Temporary_Bullet_Handler = Instantiate(Bullet,Bullet_Emitter.transform.position,Bullet_Emitter.transform.rotation) as GameObject;
Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);
Rigidbody Temporary_RigidBody;
Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent<Rigidbody>();
.
Temporary_RigidBody.AddForce(transform.right * Bullet_Forward_Force + Vector3
(Random.Range(-accuracy, accuracy)
(Random.Range(-accuracy, accuracy),0.0f ) ) );
Destroy(Temporary_Bullet_Handler, 5.0f);
}
}
}
script name has space in it.
KlVI
4
Uh, I’m such an idiot, but Thanks Guys!
You’re also going to need a ‘new’ before the Vector3 constructor on line 42.