Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

leosheiik

Newbie
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

1 Neutral

About leosheiik

  • Rank
    Newbie

Profile Information

  • Gender
    Male
  • Location:
    Brasil
  • Interests
    Develop a unity 3D FPS Game.
  1. This is the script weapon that took the internet, I just removed the trinket boxes of rocket launchers, grenades and improved indentation plus the bullet does not get away from the gun appears and she just stands there, how can I fix this please! using UnityEngine;using System.Collections;using System.Collections.Generic; public class WeaponScript : MonoBehaviour{public enum weaponType { Shotgun, Machinegun, Burst };public weaponType typeOfGun; public enum BulletType { Physical, Raycast };public BulletType typeOfBullet; public GameObject bullet; public Transform bulletspawn; public GameObject impactEffect;public GameObject bulletHole; public GameObject weaponTarget; private bool isFiring = false; public int pelletsPerShot = 10; public int roundsPerBurst = 3; public float lagBetweenShots = 0.5f; public int range = 300; public float damage = 20.0f; public float maxPenetration = 3.0f; public float fireRate = 0.5f; public int impactForce = 50; public float bulletSpeed = 200.0f; public int bulletsPerClip = 50; public int numberOfClips = 5; public int maxNumberOfClips = 10; private int bulletsLeft; public float baseSpread = 1.0f; public float maxSpread = 4.0f; public float spreadPerSecond = 0.2f; public float spread = 0.0f; public float decreaseSpreadPerSec = 0.5f; public float reloadTime = 1.0f; private bool isReloading = false; public int shotsFired = 0; public int roundsPerTracer = 1; private float nextFireTime = 0.0f; private float[] bulletInfo = new float[6]; void Start () {bulletsLeft = bulletsPerClip;} bool Update () {switch (typeOfGun) {case weaponType.Shotgun:if (Input.GetMouseButtonDown (0))ShotGun_Fire ();break;case weaponType.Machinegun:if (Input.GetMouseButton (0)) MachineGun_Fire (); break;case weaponType.Burst:if (Input.GetMouseButtonDown (0))StartCoroutine ("Burst_Fire"); break;}//=============================//if (Input.GetMouseButtonDown (0))isFiring = true; elseisFiring = false;//=============================//if (isFiring)spread += spreadPerSecond; elsespread -= decreaseSpreadPerSec;//=============================//return true;} void LateUpdate () {if (spread >= maxSpread)spread = maxSpread;elseif (spread <= baseSpread)spread = baseSpread;} void MachineGun_Fire () {if (bulletsLeft <= 0){StartCoroutine("reload");return;} if (Time.time - fireRate > nextFireTime)nextFireTime = Time.time - Time.deltaTime; while (nextFireTime < Time.time) {switch (typeOfBullet) {case BulletType.Physical:StartCoroutine("FireOneShot"); break;case BulletType.Raycast:StartCoroutine("FireOneRay"); break;default:Debug.Log("error in bullet type");break;}shotsFired++;bulletsLeft--;nextFireTime += fireRate;}} IEnumerator Burst_Fire () {int shotCounter = 0;if (bulletsLeft <= 0){StartCoroutine("reload");yield break;} if (Time.time - fireRate > nextFireTime)nextFireTime = Time.time - Time.deltaTime; while (nextFireTime < Time.time) {while (shotCounter < roundsPerBurst) {switch (typeOfBullet) {case BulletType.Physical:StartCoroutine("FireOneShot");break;case BulletType.Raycast:StartCoroutine("FireOneRay");break;default:Debug.Log("error in bullet type");break;} shotCounter++;shotsFired++;bulletsLeft--; yield return new WaitForSeconds(lagBetweenShots); }nextFireTime += fireRate;}} void ShotGun_Fire () {int pelletCounter = 0;if (bulletsLeft == 0){StartCoroutine("reload");return;} if (Time.time - fireRate > nextFireTime)nextFireTime = Time.time - Time.deltaTime; while (nextFireTime < Time.time) {do {switch (typeOfBullet) {case BulletType.Physical:StartCoroutine("FireOneShot");break;case BulletType.Raycast:StartCoroutine("FireOneRay");break;default:Debug.Log("error in bullet type");break;} pelletCounter++; shotsFired++; } while (pelletCounter < pelletsPerShot);nextFireTime += fireRate;bulletsLeft--;}} IEnumerator FireOneShot () {Vector3 position = bulletspawn.position; bulletInfo[0] = damage;bulletInfo[1] = impactForce;bulletInfo[2] = maxPenetration;bulletInfo[3] = maxSpread;bulletInfo[4] = spread;bulletInfo[5] = bulletSpeed;GameObject newBullet = Instantiate(bullet, bulletspawn.position, bulletspawn.rotation) as GameObject; if (shotsFired >= roundsPerTracer) {newBullet.renderer.enabled = true; shotsFired = 0;} else { newBullet.renderer.enabled = false; } if (audio)audio.Play(); if ((bulletsLeft == 0)){StartCoroutine("reload");yield break;}} IEnumerator FireOneRay () {string[] Info = new string[2];int hitCount = 0;bool tracerWasFired = false; Vector3 position = bulletspawn.position;Vector3 direction = bulletspawn.TransformDirection(Random.Range(-maxSpread, maxSpread) * spread, Random.Range(-maxSpread, maxSpread) * spread, 1);Vector3 dir = (weaponTarget.transform.position - position) + direction; bulletInfo[0] = damage;bulletInfo[1] = impactForce;bulletInfo[2] = maxPenetration;bulletInfo[3] = maxSpread;bulletInfo[4] = spread;bulletInfo[5] = bulletSpeed; if (shotsFired >= roundsPerTracer) {FireOneTracer(bulletInfo);shotsFired = 0;tracerWasFired = true;} RaycastHit[] hits = Physics.RaycastAll(position , dir, range); for (int i = 0; i < hits.Length; i++) {if (hitCount >= maxPenetration)yield break; RaycastHit hit = hits[i]; if (!tracerWasFired)ShowHits(hit); Info[0] = damage.ToString();hit.collider.SendMessageUpwards("ImHit", Info, SendMessageOptions.DontRequireReceiver); hitCount++;} } void FireOneTracer (float[] info) {Vector3 position = bulletspawn.position; GameObject newTracer = Instantiate(bullet, position, transform.rotation) as GameObject;} void ShowHits (RaycastHit hit) {switch (hit.transform.tag) {case "bullet": break;case "Player": break;case "wood": break;case "stone": break;case "ground": break;default:Instantiate(impactEffect, hit.point + 0.1f * hit.normal, Quaternion.FromToRotation(Vector3.up, hit.normal));GameObject newBulletHole = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject;newBulletHole.transform.parent = hit.transform;break;}} IEnumerator reload () {if (isReloading)yield break;if (numberOfClips > 0) {isReloading = true; numberOfClips--; yield return new WaitForSeconds(reloadTime);bulletsLeft = bulletsPerClip; }isReloading = false;}}
  2. This is my simple shooter script in C#. "error CS0266: Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.Rigidbody'. An explicit conversion exists (are you missing a cast?)" using UnityEngine; using System.Collections; public class WeaponScript : MonoBehaviour { public Rigidbody projectile; public Transform spawn; public float velocity; public float damage; void Start () { } void Update () { if(Input.GetMouseButton(0)) Shoot(); } void Shoot () { Rigidbody clone = Instantiate(projectile, spawn.position, spawn.rotation); clone.velocity = transform.forward * velocity; } }
  3. I put this here for decrease scripts quantity for more organization !
  4. I deleted the part of automatic weapon , so it's have only semi-automatic script. This my WeaponScript: /* ~•~•~•~•~•~•~•~•~•~•~•~• */ /* ~• Variables •~ */ /* ~•~•~•~•~•~•~•~•~•~•~•~• */ // ~ Sound Effects var fire_sound : AudioClip; var draw_sound : AudioClip; var reload_sound : AudioClip; var empty_sound : AudioClip; // ~ Animations var fire_anim : AnimationClip; var draw_anim : AnimationClip; var reload_anim : AnimationClip; // ~ Fire Rate var shoot_timer : float = 0; var count : float = 0.6; // ~ Munition var bullets : int = 07; var munitions : int = 05; var IsReloading : boolean; // ~ Delay Effect var amount : float = 0.02; var maxAmount : float = 0.03; var smooth : float = 3.00; private var def : Vector3; // ~ Aim var weap_camera : GameObject; /* ~•~•~•~•~•~•~•~•~•~•~•~• */ /* ~• Functions •~ */ /* ~•~•~•~•~•~•~•~•~•~•~•~• */ function Start () { Draw (); // ~ Delay def = transform.localPosition; // ~ Aim weap_camera.SetActive(false); // ~ Cursor Hide/Lock Screen.lockCursor = true; Screen.showCursor = false; } function Update () { Delay (); if(Input.GetMouseButtonDown(0)) { if(!IsReloading) { if(bullets > 0) { if(shoot_timer > count) { Fire (); shoot_timer = 0; } } else { audio.clip = empty_sound; audio.Play (); Reload (); } } } shoot_timer += Time.deltaTime; if(Input.GetMouseButtonDown(1)) { weap_camera.SetActive(true); } else if(Input.GetMouseButtonUp(1)) { weap_camera.SetActive(false); } if(Input.GetKeyDown(KeyCode.R)) { Reload (); } } function OnGUI () { GUI.Box(Rect(Screen.width - 110,Screen.height - 70, 100, 25), " " + bullets + " / " + munitions); } /* ~•~•~•~•~•~•~•~•~•~•~•~• */ /* ~• New Functions •~ */ /* ~•~•~•~•~•~•~•~•~•~•~•~• */ function Fire () { audio.clip = fire_sound; audio.Play (); animation.clip = fire_anim; animation.Play (); bullets--; } function Draw () { audio.clip = draw_sound; audio.Play (); animation.clip = draw_anim; animation.Play (); } function Reload () { if(munitions > 0 && bullets == 0) { yield WaitForSeconds(0.5); IsReloading = true; audio.clip = reload_sound; audio.Play (); animation.clip = reload_anim; animation.Play (); munitions--; bullets = 7; yield WaitForSeconds(2); IsReloading = false; } else if(munitions > 0 && bullets < 07) { IsReloading = true; audio.clip = reload_sound; audio.Play (); animation.clip = reload_anim; animation.Play (); munitions--; bullets = 7; yield WaitForSeconds(2); IsReloading = false; } } function Delay () { var factorX : float = -Input.GetAxis("Mouse X") * amount; var factorY : float = -Input.GetAxis("Mouse Y") * amount; if (factorX > maxAmount) factorX = maxAmount; if (factorX < -maxAmount) factorX = -maxAmount; if (factorY > maxAmount) factorY = maxAmount; if (factorY < -maxAmount) factorY = -maxAmount; var Final : Vector3 = new Vector3(def.x+factorX, def.y+factorY, def.z); transform.localPosition = Vector3.Lerp(transform.localPosition, Final, Time.deltaTime * smooth); }
  5. I tried this, but I did not understand much, because the scripts FpsKit is very confusing to me!
  6. Hello guys, Today I started making my own WeaponScript, but I'm still a newbie, and I need your help for that! I'm doing a WeaponScript weapons semi-automatic and automatic, but I'm having trouble playing the part of the automatic weapon. And I wonder if you can do a simple script for me to use the base. Must have the use of animation and sound.
×
×
  • Create New...