SchultzGames
Para tirar dúvidas, crie um tópico especifico na área "Dúvidas em Geral" e aguarde ser respondido. Evite comentar em tópicos não relacionados a sua dúvida :D
TÓPICOS RECENTES:
Tópico:
Postado em:
Postado por:
ShapeKeys do Blender para a Unity altera áreas próximas
COMO EVITAR QUE UM OBJETO (PLAYER,ITEM ETC...) ATRAVESSE UMA PAREDE.
Ajuda em Script de Verificação de Ação e Reação
unity Failed to load PlayerSettings (internal index #0). Most likely data f
modelar avatar e skins para um jogo web
PRECISO FAZER QUE MEU GAME FIQUE ONLINE
Materiais do Blander não aparecem no MeshRendere do Objeto na Unity
Repetiçoes de Textura no Terreno
SERVER IS DOWN - UNITY+MSQL
Procuro programadores - Novo jogo
Problema com o MS VEHICLES
Preciso de ajuda com a Unity
Problema com vídeo em 360° na Unity
Problemas no MS Vehicles
unity- eventos na Animação com Armature/Bones vinda do blender não funciona
ajuda exibir resultados simulados em uma liga Game Unity
Unity - ParticleSystem não é redirecionado no rawimage no canvas
Como resolver o problema de "face orientation" no Blender.
[DÚVIDA] Tive um problema com meu Canvas
erro na Directional Light
Problemas com o Directional Light da Unity 3D
210 Linhas de código para inimigo é muito grande?
Novo jogo da franquia Sphere game em desenvolvimento
malha da roda não girando com wheel collider unity
Problemas com ambiguidade
Touch mobile
INVALID TOKEN
Como acessar o "HD Render Pipeline" do HDRP por script?
CHAT GPT PRA JOGO DE TIRO? comentem
Tutorial script inimigo segue e foge do player
Ainda vale a pena lançar Asset na Asset Store?
Ajuda com tabela de historico de pontuaçao.
[TUTORIAL] Entrar no carro estilo GTA
Como derrapar um Whell Collider
Como altertar o valor do "Asymptote Value" do Whell Collider via Script
Preciso de ajuda para substituir valor de variavel em outro script
Ajuda com Top Down Shooter utilizando Photon
Duvida com Netcode
[RESOLVIDO] Unity - Movendo a Câmera na Horizontal/Vertical com Touch
Alguém me ajuda com os anúncios pfv
Segundo Trailer do jogo Dark Age, Feliz Natal a todos!
Unity - ScrollRect, Viewport, Content - O Conteúdo ñ inicia no topo
Coleta de itens
Unity - Cadastro do email do jogador
[GRATIS] PACK DE MODELOS 3D PARA JOGO DE TERROR
Onde Conseguir músicas para meu Jogo?
error CS0246 em Script
Alguem teve ja esse problema?
[Projeto em Andamento] Draug, um jogo de hordas
DISPONIVEL PARA FAZER MODELOS 3D
Unity-Loja.Como os Jogadores terão acesso aos ítens comprados na PlayStore?
Bugando depois do Build.
Primeiro Trailer do jogo Dark Age
Problema com sombra
Mesh e Material do objeto trocando para uma instancia no inicio do jogo
[RESOLVIDO] Unity - RawImages_Layer_Camera
INVESTIMENTO EM JOGOS E BANCO DE TALENTO
Teaser do meu novo projeto pessoal, Dark Age
Preciso de ajuda com mudança para mobile androide.
[RESOLVIDO] Posição final do objeto em jogo 2D
Input.GetAxis() obedercer a orientação de um objeto.
Interação com elementos UI
Meu primeiro jogo na steam
Minimap/Radar/GPS Estilo GTA V
[RESOLVIDO] Erro no console depois que formatei o pc
PACK GRÁTIS de Músicas ELETRÔNICAS para ajudar vocês em seus Jogos Indies!
[TUTORIAL] Entenda como funciona: ENUM, SWITCH, BREAK, CASE no C#
O Labirinto II - Baixe o Jogo
Qual e o codigo de Botões na unity para saber seus estados?
Como carregar itens pequenos dentro do carro sem que atravesse os colliders
[Duvida] Script pegar itens
Travamento ao trocar de cena
Colisão zoada e movimentação
Salvar objetos que foram destruidos entre cenas na unity
Quero começa a desenvolver um jogo de luta porem eu queria aprender a faze
Pegar qual objeto colidiu com o Linecast.
movimentação e camera?
[RESOLVIDO] Unity - SceneManager.LoadScene abre scene com objeto "vazio"
[RESOLVIDO] ajuda sobre skybox
MEU SIMULADOR DE CARRO
[_____IMPORTANTE_____] ALTERAÇÕES NA POLÍTICA DE COBRANÇA DA UNITY
[RESOLVIDO] Ausencia da funçao NavMesh na Unity 2022.2.12
[_____IMPORTANTE_____] ALTERAÇÕES NA POLÍTICA DE COBRANÇA DA UNITY - 2
Roll Up Um jogo de aventura e desáfios
Terminologia da Unity em outras engines
Como criar a iluminação do Sol no Sistema Solar?
Conexão de lobby pelo OnConnectedToMaster
Problema na exportção de projeto unity
[RESOLVIDO] Unity - Áudios estão emitindo som só Depois do Botão ser solto
Unity - Banco de Dados Online junto ao Jogo
Player virar para o inimigo(Prefab)
[TUTORIAL] Sistema De Save Game Ao Sair Da Fase
Problema de Sincronização de um objeto de um jogo multiplayer usa q Photon
Unity - Compartilhar meu Jogo
Alguém que manja do Google ADmob?
Unity - Avaliar meu Jogo
[RESOLVIDO] Destruir inimigo com o player.
Salvar e carregar dados na Unity de objetos prefabs sem sobrescrever os dad
Unity - Salvar os Dados do Jogador Online
Ontem à(s) 10:09 pm
Dom Mar 10, 2024 2:30 pm
Sex Mar 01, 2024 1:27 pm
Qui Fev 22, 2024 9:57 pm
Qua Fev 21, 2024 10:39 am
Ter Fev 20, 2024 9:28 am
Ter Fev 20, 2024 12:15 am
Seg Fev 19, 2024 1:06 pm
Seg Fev 12, 2024 1:56 pm
Seg Fev 12, 2024 1:17 pm
Dom Fev 11, 2024 8:55 pm
Dom Fev 11, 2024 11:16 am
Seg Fev 05, 2024 4:18 pm
Dom Fev 04, 2024 9:39 pm
Qua Jan 31, 2024 11:59 pm
Ter Jan 30, 2024 7:37 pm
Ter Jan 23, 2024 6:33 pm
Dom Jan 21, 2024 6:03 pm
Sáb Jan 20, 2024 7:03 pm
Sáb Jan 20, 2024 6:58 pm
Sáb Jan 20, 2024 6:39 pm
Sex Jan 19, 2024 1:29 pm
Sex Jan 19, 2024 8:40 am
Dom Jan 14, 2024 5:30 pm
Qua Jan 10, 2024 10:29 pm
Qua Jan 10, 2024 8:55 pm
Qua Jan 10, 2024 7:14 pm
Ter Jan 09, 2024 3:55 pm
Ter Jan 09, 2024 8:04 am
Sáb Jan 06, 2024 8:02 pm
Sex Jan 05, 2024 7:01 am
Sex Jan 05, 2024 12:12 am
Qui Jan 04, 2024 6:55 pm
Qui Jan 04, 2024 12:52 pm
Qui Jan 04, 2024 4:34 am
Ter Jan 02, 2024 11:48 pm
Dom Dez 31, 2023 7:25 pm
Qua Dez 27, 2023 5:44 pm
Qua Dez 27, 2023 3:08 pm
Sáb Dez 23, 2023 7:27 pm
Sáb Dez 23, 2023 5:06 pm
Qui Dez 21, 2023 8:10 pm
Seg Dez 18, 2023 2:04 pm
Sex Dez 15, 2023 5:11 pm
Qui Dez 14, 2023 9:13 pm
Qui Dez 14, 2023 2:47 pm
Qui Dez 14, 2023 1:48 pm
Qua Dez 13, 2023 8:58 pm
Ter Dez 12, 2023 2:32 pm
Seg Dez 11, 2023 1:53 pm
Qua Dez 06, 2023 8:13 pm
Sáb Dez 02, 2023 8:06 pm
Qui Nov 30, 2023 7:49 am
Seg Nov 27, 2023 1:35 am
Qua Nov 22, 2023 7:37 am
Qui Nov 09, 2023 1:22 pm
Seg Nov 06, 2023 11:59 am
Ter Out 31, 2023 9:53 am
Dom Out 29, 2023 8:05 pm
Dom Out 29, 2023 3:03 am
Sex Out 27, 2023 3:43 pm
Sex Out 27, 2023 3:28 pm
Qua Out 25, 2023 1:20 pm
Seg Out 23, 2023 10:34 am
Dom Out 22, 2023 6:55 pm
Qui Out 19, 2023 11:57 pm
Qui Out 19, 2023 6:39 pm
Ter Out 17, 2023 6:37 pm
Ter Out 17, 2023 6:18 pm
Seg Out 16, 2023 1:59 pm
Sáb Out 14, 2023 12:15 pm
Qua Out 11, 2023 6:07 pm
Seg Out 09, 2023 4:19 pm
Qua Out 04, 2023 12:12 pm
Qua Out 04, 2023 12:11 pm
Ter Out 03, 2023 9:18 pm
Ter Out 03, 2023 9:08 pm
Ter Out 03, 2023 6:05 pm
Ter Set 26, 2023 12:45 pm
Seg Set 25, 2023 9:02 pm
Seg Set 25, 2023 9:47 am
Sáb Set 23, 2023 2:10 pm
Sex Set 22, 2023 9:01 pm
Qui Set 21, 2023 11:04 am
Qua Set 20, 2023 4:40 pm
Qua Set 20, 2023 9:15 am
Dom Set 17, 2023 12:17 pm
Sex Set 15, 2023 7:24 pm
Sex Set 15, 2023 5:41 pm
Sex Set 15, 2023 4:28 pm
Sex Set 15, 2023 10:56 am
Sex Set 15, 2023 10:15 am
Seg Set 11, 2023 11:43 am
Seg Set 11, 2023 11:31 am
Sáb Set 09, 2023 4:53 pm
Sáb Set 09, 2023 1:44 pm
Ter Set 05, 2023 11:12 pm
Ter Set 05, 2023 3:12 pm
Seg Set 04, 2023 11:53 pm



































































































Recarregador de armas

5 participantes

Ir para baixo

Resolvido Recarregador de armas

Mensagem por Callyde Jr Qua Jan 18, 2017 6:42 am

Heae amigos blz
Estou aqui com um sistema de armas sao uma pistola e um rifre estou tentando fazer um carregador para elas mais nao deu certo um script das armas fica no Player e o outro em cada arma

Código:
//script da arma

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Collider))]
[RequireComponent(typeof(Rigidbody))]
public class Weapon : MonoBehaviour
{
 private Collider col { get { return GetComponent<Collider> (); } set { col = value; } }
 private Rigidbody rigidBody { get { return  GetComponent<Rigidbody> (); } set { rigidBody = value; } }
 private Animator animator { get { return GetComponent<Animator> (); } set { animator = value; } }
 private SoundController sc;

    public enum WeaponType
    {
        Pistol, Rifle
    }
    public WeaponType weaponType;

    [System.Serializable]
    public class UserSettings
    {
        public Transform leftHandIKTarget;
        public Vector3 spineRotation;
    }
    [SerializeField]
    public UserSettings userSettings;

    [System.Serializable]
    public class WeaponSettings
    {
        [Header("-Bullet Options-")]
        public Transform bulletSpawn;
        public float damage = 5.0f;
        public float bulletSpread = 5.0f;
        public float fireRate = 0.2f;
        public LayerMask bulletLayers;
        public float range = 200.0f;

        [Header("-Effects-")]
        public GameObject muzzleFlash;
        public GameObject decal;
        public GameObject shell;
        public GameObject clip;

        [Header("-Other-")]
 public GameObject crosshairPrefab;
        public float reloadDuration = 2.0f;
        public Transform shellEjectSpot;
        public float shellEjectSpeed = 7.5f;
        public Transform clipEjectPos;
        public GameObject clipGO;

        [Header("-Positioning-")]
        public Vector3 equipPosition;
        public Vector3 equipRotation;
        public Vector3 unequipPosition;
        public Vector3 unequipRotation;

        [Header("-Animation-")]
        public bool useAnimation;
        public int fireAnimationLayer = 0;
        public string fireAnimationName = "Fire";
    }
    [SerializeField]
    public WeaponSettings weaponSettings;

    [System.Serializable]
    public class Ammunition
    {
        public int carryingAmmo;
        public int clipAmmo;
        public int maxClipAmmo;
    }
    [SerializeField]
    public Ammunition ammo;

    WeaponHandler owner;
    bool equipped;
    bool resettingCartridge;

 [System.Serializable]
 public class SoundSettings {
 public AudioClip[] gunshotSounds;
 public AudioClip reloadSound;
 [Range(0, 3)] public float pitchMin = 1;
 [Range(0, 3)] public float pitchMax = 1.2f;
 public AudioSource audioS;
 }
 [SerializeField]
 public SoundSettings sounds;

    // Use this for initialization
    void Start()
    {
 GameObject check = GameObject.FindGameObjectWithTag ("Sound Controller");

 if (check != null) {
 sc = check.GetComponent<SoundController> ();
 }

    }

    // Update is called once per frame
    void Update()
    {
        if (owner) {
            DisableEnableComponents(false);
            if (equipped) {
                if (owner.userSettings.rightHand) {
                    Equip();
                }
            } else {
 if (weaponSettings.bulletSpawn.childCount > 0) {
 foreach (Transform t in weaponSettings.bulletSpawn.GetComponentsInChildren<Transform>()) {
 if (t != weaponSettings.bulletSpawn) {
 Destroy (t.gameObject);
 }
 }
 }
                Unequip(weaponType);
            }
        } else { // If owner is null
            DisableEnableComponents(true);
            transform.SetParent(null);
        }
    }

    //This fires the weapon
    public void Fire(Ray ray)
    {
 if (ammo.clipAmmo <= 0 || resettingCartridge || !weaponSettings.bulletSpawn || !equipped)
            return;

        RaycastHit hit;
        Transform bSpawn = weaponSettings.bulletSpawn;
        Vector3 bSpawnPoint = bSpawn.position;
 Vector3 dir = ray.GetPoint(weaponSettings.range) - bSpawnPoint;

        dir += (Vector3)Random.insideUnitCircle * weaponSettings.bulletSpread;

        if(Physics.Raycast(bSpawnPoint, dir, out hit, weaponSettings.range, weaponSettings.bulletLayers))
        {
 HitEffects (hit);

 if (hit.transform.root.GetComponent<CharacterStats> ()) {
 hit.transform.root.SendMessage("Damage",weaponSettings.damage);
 
 }
 }

 GunEffects ();

        if (weaponSettings.useAnimation)
            animator.Play(weaponSettings.fireAnimationName, weaponSettings.fireAnimationLayer);

        ammo.clipAmmo--;
        resettingCartridge = true;
        StartCoroutine(LoadNextBullet());
    }

    //Loads the next bullet into the chamber
    IEnumerator LoadNextBullet()
    {
        yield return new WaitForSeconds(weaponSettings.fireRate);
        resettingCartridge = false;
    }

 void HitEffects(RaycastHit hit)
 {
 if (hit.collider.gameObject.isStatic)
 {
 if (weaponSettings.decal)
 {
 Vector3 hitPoint = hit.point;
 Quaternion lookRotation = Quaternion.LookRotation(hit.normal);
 GameObject decal = Instantiate(weaponSettings.decal, hitPoint, lookRotation) as GameObject;
 Transform decalT = decal.transform;
 Transform hitT = hit.transform;
 decalT.SetParent(hitT);
 Destroy(decal, Random.Range(15.0f, 20.0f));
 }
 }
 }

 void GunEffects()
 {
 if (weaponSettings.muzzleFlash)
 {
 Vector3 bulletSpawnPos = weaponSettings.bulletSpawn.position;
 GameObject muzzleFlash = Instantiate(weaponSettings.muzzleFlash, bulletSpawnPos, Quaternion.identity) as GameObject;
 Transform muzzleT = muzzleFlash.transform;
 muzzleT.SetParent(weaponSettings.bulletSpawn);
 Destroy(muzzleFlash, 2.0f);
 }

 if (weaponSettings.shell)
 {
 if (weaponSettings.shellEjectSpot)
 {
 Vector3 shellEjectPos = weaponSettings.shellEjectSpot.position;
 Quaternion shellEjectRot = weaponSettings.shellEjectSpot.rotation;
 GameObject shell = Instantiate(weaponSettings.shell, shellEjectPos, shellEjectRot) as GameObject;

 if (shell.GetComponent<Rigidbody>())
 {
 Rigidbody rigidB = shell.GetComponent<Rigidbody>();
 rigidB.AddForce(weaponSettings.shellEjectSpot.forward * weaponSettings.shellEjectSpeed, ForceMode.Impulse);
 }

 Destroy(shell, Random.Range(15.0f, 20.0f));
 }
 }

 PlayGunshotSound ();
 }

 void PlayGunshotSound () {
 if (sc == null) {
 return;
 }

 if (sounds.audioS != null) {
 if (sounds.gunshotSounds.Length > 0) {
 sc.InstantiateClip (
 weaponSettings.bulletSpawn.position, // Where we want to play the sound from
 sounds.gunshotSounds [Random.Range (0, sounds.gunshotSounds.Length)],  // What audio clip we will use for this sound
 2, // How long before we destroy the audio
 true, // Do we want to randomize the sound?
 sounds.pitchMin, // The minimum pitch that the sound will use.
 sounds.pitchMax); // The maximum pitch that the sound will use.
 }
 }
 }

    //Disables or enables collider and rigidbody
    void DisableEnableComponents(bool enabled)
    {
        if(!enabled)
        {
            rigidBody.isKinematic = true;
            col.enabled = false;
        }
        else
        {
            rigidBody.isKinematic = false;
            col.enabled = true;
        }
    }

    //Equips this weapon to the hand
    void Equip()
    {
        if (!owner)
            return;
        else if (!owner.userSettings.rightHand)
            return;

        transform.SetParent(owner.userSettings.rightHand);
        transform.localPosition = weaponSettings.equipPosition;
        Quaternion equipRot = Quaternion.Euler(weaponSettings.equipRotation);
        transform.localRotation = equipRot;
    }
    
    //Unequips the weapon and places it to the desired location
    void Unequip(WeaponType wpType)
    {
        if (!owner)
            return;

        switch (wpType)
        {
            case WeaponType.Pistol:
                transform.SetParent(owner.userSettings.pistolUnequipSpot);
                break;
            case WeaponType.Rifle:
                transform.SetParent(owner.userSettings.rifleUnequipSpot);
                break;
        }
        transform.localPosition = weaponSettings.unequipPosition;
        Quaternion unEquipRot = Quaternion.Euler(weaponSettings.unequipRotation);
        transform.localRotation = unEquipRot;
    }

    //Loads the clip and calculates the ammo
    public void LoadClip()
    {
        int ammoNeeded = ammo.maxClipAmmo - ammo.clipAmmo;

        if(ammoNeeded >= ammo.carryingAmmo)
        {
            ammo.clipAmmo = ammo.carryingAmmo;
            ammo.carryingAmmo = 0;
        }
        else
        {
            ammo.carryingAmmo -= ammoNeeded;
            ammo.clipAmmo = ammo.maxClipAmmo;
        }
    }

    //Sets the weapons equip state
    public void SetEquipped(bool equip)
    {
        equipped = equip;
    }

    //Sets the owner of this weapon
    public void SetOwner(WeaponHandler wp)
    {
        owner = wp;
    }
}


Código:
//script do player
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class WeaponHandler : MonoBehaviour
{
 private Animator animator { get { return GetComponent<Animator> (); } set { animator = value; } }
 private SoundController sc;

 public bool isAI;

    [System.Serializable]
    public class UserSettings
    {
        public Transform rightHand;
        public Transform pistolUnequipSpot;
        public Transform rifleUnequipSpot;
    }
    [SerializeField]
    public UserSettings userSettings;

    [System.Serializable]
    public class Animations
    {
        public string weaponTypeInt = "WeaponType";
        public string reloadingBool = "isReloading";
        public string aimingBool = "Aiming";
    }
    [SerializeField]
    public Animations animations;

    public Weapon currentWeapon;
    public List<Weapon> weaponsList = new List<Weapon>();
    public int maxWeapons = 2;
    public bool aim { get; protected set; }
 private bool reload;
 private int weaponType;
    private bool settingWeapon;

    // Use this for initialization
    void OnEnable()
    {
 GameObject check = GameObject.FindGameObjectWithTag ("Sound Controller");
 if (check != null)
 sc = check.GetComponent<SoundController> ();
      
 SetupWeapons ();
    }

 void SetupWeapons () {
 if (currentWeapon)
 {
 currentWeapon.SetEquipped(true);
 currentWeapon.SetOwner(this);
 AddWeaponToList(currentWeapon);

 if (currentWeapon.ammo.clipAmmo <= 0)
 Reload();

 if (reload)
 if (settingWeapon)
 reload = false;
 }

 if(weaponsList.Count > 0)
 {
 for(int i = 0; i < weaponsList.Count; i++)
 {
 if(weaponsList[i] != currentWeapon)
 {
 weaponsList[i].SetEquipped(false);
 weaponsList[i].SetOwner(this);
 }
 }
 }
 }

    // Update is called once per frame
    void Update()
    {
        Animate();
    }

    //Animates the character
    void Animate()
    {
        if (!animator)
            return;

        animator.SetBool(animations.aimingBool, aim);
        animator.SetBool(animations.reloadingBool, reload);
        animator.SetInteger(animations.weaponTypeInt, weaponType);

        if (!currentWeapon)
        {
            weaponType = 0;
            return;
        }

        switch (currentWeapon.weaponType)
        {
            case Weapon.WeaponType.Pistol:
                weaponType = 1;
                break;
            case Weapon.WeaponType.Rifle:
                weaponType = 2;
                break;
        }
    }

    //Adds a weapon to the weaponsList
    void AddWeaponToList(Weapon weapon)
    {
        if (weaponsList.Contains(weapon))
            return;

        weaponsList.Add(weapon);
    }

    //Puts the finger on the trigger and asks if we pulled
 public void FireCurrentWeapon (Ray aimRay)
    {
 if (currentWeapon.ammo.clipAmmo == 0) {
 Reload ();
 return;
 }

 currentWeapon.Fire (aimRay);
    }

    //Reloads the current weapon
    public void Reload()
    {
        if (reload || !currentWeapon)
            return;

        if (currentWeapon.ammo.carryingAmmo <= 0 || currentWeapon.ammo.clipAmmo == currentWeapon.ammo.maxClipAmmo)
            return;

 if (sc != null) {
 if (currentWeapon.sounds.reloadSound != null) {
 if (currentWeapon.sounds.audioS != null) {
 sc.PlaySound (currentWeapon.sounds.audioS, currentWeapon.sounds.reloadSound, true, currentWeapon.sounds.pitchMin, currentWeapon.sounds.pitchMax);
 }
 }
 }

        reload = true;
        StartCoroutine(StopReload());
    }

    //Stops the reloading of the weapon
    IEnumerator StopReload()
    {
        yield return new WaitForSeconds(currentWeapon.weaponSettings.reloadDuration);
        currentWeapon.LoadClip();
        reload = false;
    }

    //Sets out aim bool to be what we pass it
    public void Aim(bool aiming)
    {
        aim = aiming;
    }

    //Drops the current weapon
    public void DropCurWeapon()
    {
        if (!currentWeapon)
            return;

        currentWeapon.SetEquipped(false);
        currentWeapon.SetOwner(null);
        weaponsList.Remove(currentWeapon);
        currentWeapon = null;
    }

    //Switches to the next weapon
    public void SwitchWeapons()
 {
        if (settingWeapon || weaponsList.Count == 0)
            return;

        if (currentWeapon)
        {
            int currentWeaponIndex = weaponsList.IndexOf(currentWeapon);
            int nextWeaponIndex = (currentWeaponIndex + 1) % weaponsList.Count;

            currentWeapon = weaponsList[nextWeaponIndex];
        }
        else
        {
            currentWeapon = weaponsList[0];
        }
        settingWeapon = true;
        StartCoroutine(StopSettingWeapon());

 SetupWeapons ();
    }

    //Stops swapping weapons
    IEnumerator StopSettingWeapon()
    {
        yield return new WaitForSeconds(0.7f);
        settingWeapon = false;
    }

    void OnAnimatorIK()
    {
        if (!animator)
            return;

        if (currentWeapon &&
 currentWeapon.userSettings.leftHandIKTarget &&
 weaponType == 2 &&
 !reload &&
 !settingWeapon &&
 !isAI)
        {
            animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1);
            animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1);
            Transform target = currentWeapon.userSettings.leftHandIKTarget;
            Vector3 targetPos = target.position;
            Quaternion targetRot = target.rotation;
            animator.SetIKPosition(AvatarIKGoal.LeftHand, targetPos);
            animator.SetIKRotation(AvatarIKGoal.LeftHand, targetRot);
        }
        else
        {
            animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 0);
            animator.SetIKRotationWeight(AvatarIKGoal.LeftHand, 0);
        }
    }
}

Bom dia e obrigado


Última edição por Callyde Jr em Qui Jan 26, 2017 1:07 pm, editado 1 vez(es)
Callyde Jr
Callyde Jr
Programador

Masculino PONTOS : 4919
REPUTAÇÃO : 444
Idade : 45
Áreas de atuação : Iniciante em modelagem Blender,Sketchup
Programador
Idealista

Meu Canal
https://www.youtube.com/ch
Respeito as regras : Recarregador de armas WvDYdlf

http://unnygames.000webhostapp.com/

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por dstaroski Qua Jan 18, 2017 8:41 am

Bom dia cara! uma observação, você abriu o tópico na área errada, em "Formação de equipes". 

Abraço!
dstaroski
dstaroski
Instrutor

Masculino PONTOS : 6052
REPUTAÇÃO : 1123
Idade : 34
Áreas de atuação : Teologia, Unity 3D, C#, HTML, CSS, Dart, Flutter.

Respeito as regras : Recarregador de armas Aad8pUi

http://diegodeoliveira.gamejolt.io/defeattheilluminatis

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por JohnRambo Qua Jan 18, 2017 8:43 am

Que parte não está dando certo?
JohnRambo
JohnRambo
Moderador

Masculino PONTOS : 4927
REPUTAÇÃO : 661
Idade : 23
Áreas de atuação : Unity;
Programação;
Música e Sonorização;
Graduado em Análise e Desenvolvimento de Sistemas;
Respeito as regras : Recarregador de armas Aad8pUi

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por AndyShow Qua Jan 18, 2017 9:20 am

Tópico Movido para Duvidas em Geral!
AndyShow
AndyShow
Profissional
Profissional

Masculino PONTOS : 4699
REPUTAÇÃO : 580
Idade : 41
Áreas de atuação : Blender e Unity
Respeito as regras : Recarregador de armas WvDYdlf

http://mundounity3d.forumbom.com/

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por Callyde Jr Qua Jan 18, 2017 1:25 pm

Obrigado por corrigir o meu erro no topico.
Bom eu estava tentando fazer um recarregador ingual aquele que o Marcos fez nesse  Tutorial 
O script da muniçao que marcos fez e esse queria modificalo para meu sistema.
Callyde Jr
Callyde Jr
Programador

Masculino PONTOS : 4919
REPUTAÇÃO : 444
Idade : 45
Áreas de atuação : Iniciante em modelagem Blender,Sketchup
Programador
Idealista

Meu Canal
https://www.youtube.com/ch
Respeito as regras : Recarregador de armas WvDYdlf

http://unnygames.000webhostapp.com/

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por Callyde Jr Sáb Jan 21, 2017 6:34 am

Eu estou tentando faze-lo assim
Código:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

[RequireComponent(typeof(Collider))]
public class Municao : MonoBehaviour {

 
  private Collider col { get { return GetComponent<Collider> (); } set { col = value; } }
  private WeaponHandler wp { get { return Player.GetComponent<WeaponHandler> (); } set { wp = value; } }

 
  public Transform Player;
  public float Recarregar = 2;
  public bool Ativar;
  public KeyCode TeclaPegarMunicao = KeyCode.E;
  public AudioClip SomPegarMunicao;
  public float distanciaDoItem = 3;
  bool podePegarOItem;
  AudioSource emissorSom;
   
   // Use this for initialization
   void Start () {
   Ativar = false;
   emissorSom = GetComponent<AudioSource> ();
   
   }
   
   // Update is called once per frame
   void Update () {
   float distancia = Vector3.Distance (transform.position, Player.gameObject.transform.position);
    if (distancia < distanciaDoItem) {
    podePegarOItem = true;
    } else {
    podePegarOItem = false;
    }   
      
   if (Input.GetKeyDown (TeclaPegarMunicao) && podePegarOItem) {
   Ativar = true;
    if(Player.gameObject.GetComponent<Weapon> ()) {
       if (wp)
            {
         if (wp.weaponType.currentWeapon == null) {
    wp.weaponType.currentWeapon.ammo.carryingAmmo + Recarregar;// Aqui vc Declara o Sist de Vida do Player e o Dano que ele Vai Receber
  }
      
   
     GameObject emissorSom = new GameObject ();
      emissorSom.AddComponent (typeof(AudioSource));
      emissorSom.GetComponent<AudioSource> ().PlayOneShot (SomPegarMunicao);
      Destroy (emissorSom.gameObject, 5);
      Destroy (gameObject);
    }
   }
   }
   }
   
 void OnGUI(){
 if (podePegarOItem == true) {
 GUIStyle stylez = new GUIStyle ();
 stylez.alignment = TextAnchor.MiddleCenter;
 GUI.skin.label.fontSize = 20;
 GUI.Label (new Rect (Screen.width / 2 - 50, Screen.height / 2 + 50, 200, 30), "Pressione: " + TeclaPegarMunicao);
 }
 
 }
 
   
}

para meu sistema de vida deu certo para o de armas esta dando erros
Callyde Jr
Callyde Jr
Programador

Masculino PONTOS : 4919
REPUTAÇÃO : 444
Idade : 45
Áreas de atuação : Iniciante em modelagem Blender,Sketchup
Programador
Idealista

Meu Canal
https://www.youtube.com/ch
Respeito as regras : Recarregador de armas WvDYdlf

http://unnygames.000webhostapp.com/

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por Weslley Sáb Jan 21, 2017 1:09 pm

você esta usando abstração para fazer as armas ?
Weslley
Weslley
Moderador

Masculino PONTOS : 5477
REPUTAÇÃO : 742
Idade : 26
Áreas de atuação : Inversión, Desarrollo, Juegos e Web
Respeito as regras : Recarregador de armas Aad8pUi

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por Callyde Jr Sáb Jan 21, 2017 1:45 pm

Opa boa tarde amigo
abstração?
No script da arma essas sao onde indica balas,  balaextras, e TipodeArmas.
weaponType //tipo da arma
carryingAmmo //balas extras
clipAmmo //balas
maxClipAmmo //maximodebalas

o script WeaponHandler que eu postei fica no Player e o script Weapon fica nas armas que sao duas pistola e rifre.
Callyde Jr
Callyde Jr
Programador

Masculino PONTOS : 4919
REPUTAÇÃO : 444
Idade : 45
Áreas de atuação : Iniciante em modelagem Blender,Sketchup
Programador
Idealista

Meu Canal
https://www.youtube.com/ch
Respeito as regras : Recarregador de armas WvDYdlf

http://unnygames.000webhostapp.com/

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por Callyde Jr Qua Jan 25, 2017 6:37 am

Bom dia amigos

Fiz ele assim nao deu erros mais nao adiciona a muniçao extra
Código:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

[RequireComponent(typeof(Collider))]
public class Municao : MonoBehaviour {

  private CharacterStats cs { get { return Player.GetComponent<CharacterStats> (); } set { cs = value; } }
  private Collider col { get { return GetComponent<Collider> (); } set { col = value; } }
  private WeaponHandler wp { get { return Player.GetComponent<WeaponHandler> (); } set { wp = value; } }

  public int weaponType;
  public GameObject Weapon;
  public Transform Player;
  public float Recarregar = 2;
  public bool Ativar;
  public KeyCode TeclaPegarMunicao = KeyCode.E;
  public AudioClip SomPegarMunicao;
  public float distanciaDoItem = 3;
  bool podePegarOItem;
  AudioSource emissorSom;
   
   // Use this for initialization
   void Start () {
   Ativar = false;
   emissorSom = GetComponent<AudioSource> ();
   
   }
   
   // Update is called once per frame
   void Update () {
   float distancia = Vector3.Distance (transform.position, Player.gameObject.transform.position);
    if (distancia < distanciaDoItem) {
    podePegarOItem = true;
    } else {
    podePegarOItem = false;
    }   
      
      if (Input.GetKeyDown (TeclaPegarMunicao) && podePegarOItem) {
      
   if (Weapon.gameObject.GetComponent<WeaponHandler> ()) {         
     wp.currentWeapon.ammo.carryingAmmo = wp.currentWeapon.ammo.carryingAmmo + Recarregar;
     GameObject emissorSom = new GameObject ();
      emissorSom.AddComponent (typeof(AudioSource));
      emissorSom.GetComponent<AudioSource> ().PlayOneShot (SomPegarMunicao);
      Destroy (emissorSom.gameObject, 5);
      Destroy (gameObject);
    }
   
      }
   }
   
   
 void OnGUI(){
 if (podePegarOItem == true) {
 GUIStyle stylez = new GUIStyle ();
 stylez.alignment = TextAnchor.MiddleCenter;
 GUI.skin.label.fontSize = 20;
 GUI.Label (new Rect (Screen.width / 2 - 50, Screen.height / 2 + 50, 200, 30), "Pressione: " + TeclaPegarMunicao);
 }
 
 }
 
 
}
Callyde Jr
Callyde Jr
Programador

Masculino PONTOS : 4919
REPUTAÇÃO : 444
Idade : 45
Áreas de atuação : Iniciante em modelagem Blender,Sketchup
Programador
Idealista

Meu Canal
https://www.youtube.com/ch
Respeito as regras : Recarregador de armas WvDYdlf

http://unnygames.000webhostapp.com/

Ir para o topo Ir para baixo

Resolvido Re: Recarregador de armas

Mensagem por Callyde Jr Qui Jan 26, 2017 1:05 pm

Boa tarde a todos
Consegui concertar o script agora esta funcionando direitinho

Código:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;

[RequireComponent(typeof(Collider))]
public class Municao : MonoBehaviour {

  private CharacterStats cs { get { return Player.GetComponent<CharacterStats> (); } set { cs = value; } }
  private Collider col { get { return GetComponent<Collider> (); } set { col = value; } }
  private WeaponHandler wp { get { return Player.GetComponent<WeaponHandler> (); } set { wp = value; } }

  public enum WeaponType
    {
        Pistol, Rifle
    }
  public WeaponType weaponType;
  public List<Weapon> weaponsList = new List<Weapon>();
 
  public Transform Player;
  public float Recarregar = 2;
  public bool Ativar;
  public KeyCode TeclaPegarMunicao = KeyCode.E;
  public AudioClip SomPegarMunicao;
  public float distanciaDoItem = 3;
  bool podePegarOItem;
  AudioSource emissorSom;
   
   // Use this for initialization
   void Start () {
   Ativar = false;
   emissorSom = GetComponent<AudioSource> ();
   
   }
   
   // Update is called once per frame
   void Update () {
   float distancia = Vector3.Distance (transform.position, Player.gameObject.transform.position);
    if (distancia < distanciaDoItem) {
    podePegarOItem = true;
    } else {
    podePegarOItem = false;
    }   
      
      if (Input.GetKeyDown (TeclaPegarMunicao) && podePegarOItem) {
      
   if (Player.gameObject.GetComponent<WeaponHandler> ()) {         
     wp.currentWeapon.ammo.carryingAmmo = wp.currentWeapon.ammo.carryingAmmo + Recarregar;
    
     GameObject emissorSom = new GameObject ();
      emissorSom.AddComponent (typeof(AudioSource));
      emissorSom.GetComponent<AudioSource> ().PlayOneShot (SomPegarMunicao);
      Destroy (emissorSom.gameObject, 5);
      Destroy (gameObject);
    }
   
      }
   }
   
   
 void OnGUI(){
 if (podePegarOItem == true) {
 GUIStyle stylez = new GUIStyle ();
 stylez.alignment = TextAnchor.MiddleCenter;
 GUI.skin.label.fontSize = 20;
 GUI.Label (new Rect (Screen.width / 2 - 50, Screen.height / 2 + 50, 200, 30), "Pressione: " + TeclaPegarMunicao);
 }
 
 }
 
 
}

no script da arma eu modifiquei para float essa parte
carryingAmmo //balas extras
clipAmmo //balas

Adicione essa parte ao script do carregador
 public enum WeaponType
    {
        Pistol, Rifle
    }
   public WeaponType weaponType;
   public List<Weapon> weaponsList = new List<Weapon>();

Pronto esta resolvido obrigado amigos.
Callyde Jr
Callyde Jr
Programador

Masculino PONTOS : 4919
REPUTAÇÃO : 444
Idade : 45
Áreas de atuação : Iniciante em modelagem Blender,Sketchup
Programador
Idealista

Meu Canal
https://www.youtube.com/ch
Respeito as regras : Recarregador de armas WvDYdlf

http://unnygames.000webhostapp.com/

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos