Greetings readers, I’m jeffry, I’m new on this forum and i have some questions because my unity is kinda messed up. I’m working on a FPS game and i need to add some weapons, I got like 2 weapons added but the third one i can’t do. THe third weapon is a sniper rifle.
(i cant even let it fire ) i’m new to this , followed like 40 tutorials and i can make a game now. But my problem with the rifle is i cant make it on my Nr.3 key and i cant make it even fire, ( i have all the scripts already but it just wont work. ) My second problem is : I want to build run my game. After i did that and im going to let it run. When it’s running i can online look around, i cant move i cant shoot , but when i play it in the preview it does. My last problem is : I was looking a tutorial where they made robots as enemies, i know how to do that all but when i run the game the robots just fall together and run around killing themselfs ( L.O.L ). Anyone got any ways to solve these problems? i’ll add the code of the sniper here. Thank You! ![]()
var weapons : GameObject[];
static var autoFire : boolean;
private var canKickback : boolean = true;
var selectedWeapon : int;
function Start () {
// Select the first weapon
SelectWeapon(3);
}
function LateUpdate () {
if(Input.GetButtonDown ("Fire1") canKickback){
BroadcastMessage("KickbackZ");
canKickback = false;
} else if(Input.GetButtonUp("Fire1")){
BroadcastMessage("ceaseFiring");
canKickback = true;
}
}
function Update () {
if (!Input.GetButton ("Fire1"))
BroadcastMessage("Cooldown");
// Did the user press fire?
if (Input.GetButton ("Fire1") autoFire){
BroadcastMessage("Fire");
} else if(Input.GetButtonDown ("Fire1")){
BroadcastMessage("Fire");
}
if(!aimmode.canSwitchWeaponAim)
return;
if (Input.GetKeyDown("1") weapons.length >= 1) {
if(!weapons[0].gameObject.GetComponent("weaponlocking").isLocked){
SelectWeapon(0);
selectedWeapon = 0;
}
} else if (Input.GetKeyDown("2") weapons.length >= 2) {
if(!weapons[1].gameObject.GetComponent("weaponlocking").isLocked){
SelectWeapon(1);
selectedWeapon = 1;
}
} else if (Input.GetKeyDown("3") weapons.length >= 3) {
if(!weapons[2].gameObject.GetComponent("weaponlocking").isLocked){
SelectWeapon(2);
selectedWeapon = 2;
}
if (Input.GetButtonDown("Reload"))
BroadcastMessage("Reload");
}
function SelectWeapon (index : int) {
for (var i : int=0 ;i<weapons.length; i++) {
// Activate the selected weapon
if (i == index){
weapons[i].gameObject.BroadcastMessage("selectWeapon");
// Deactivate all other weapons
}else{
weapons[i].gameObject.BroadcastMessage("deselectWeapon");
}
}
}function FullAuto () {
autoFire = true;
}
function SemiAuto () {
autoFire = false;
}
function deactivateWeapons(){
for (var i : int=0 ;i<weapons.length; i++) {
weapons[i].gameObject.BroadcastMessage("deselectWeapon");
}
}
function setWeapon (gun : GameObject, element : int){
weapons[element] = gun;
}