예제 #1
0
        /// <summary>
        /// Shooting using RayCast.
        /// </summary>
        protected virtual void RayBulletShootingProcess()
        {
            RaycastHit raycastHit;

            for (int i = 0; i < rayBullet.GetNumberBullet(); i++)
            {
                if (rayBullet.GetNumberBullet() > 1)
                {
                    firePoint.localRotation = SpreadProperties.GetSpreadRotation(-rayBullet.GetVariance(), rayBullet.GetVariance());
                }
                if (Physics.Raycast(firePoint.position, firePoint.forward, out raycastHit, fireRange))
                {
                    Debug.DrawLine(firePoint.position, firePoint.forward, Color.red);
                    Transform hitTransform = raycastHit.transform;
                    SendDamage(hitTransform, rayBullet.GetDamage());
                    if (rayBullet.GetDecalProperties() != null)
                    {
                        DecalProperty decalProperty    = DecalHelper.GetDecalPropertyBySurface(rayBullet.GetDecalProperties(), raycastHit);
                        GameObject    decal            = decalProperty.GetRandomDecal();
                        AudioClip     decalSoundEffect = decalProperty.GetRandomSound();
                        if (decal != null)
                        {
                            PoolManager.Instantiate(decal, raycastHit.point, Quaternion.LookRotation(raycastHit.normal));
                        }
                        if (decalSoundEffect != null)
                        {
                            audioSource.PlayOneShot(decalSoundEffect);
                        }
                    }
                    AddImpulse(transform, raycastHit.point);
                }
            }
        }
예제 #2
0
        protected virtual void DoShoot()
        {
            if (targetCache == null)
            {
                return;
            }

            ApplySpread();
            if (bullet.GetNumberBullet() < 100)
            {
                firePoint.localRotation = Quaternion.Euler(Random.Range(-bullet.GetVariance(), bullet.GetVariance()), Random.Range(-bullet.GetVariance(), bullet.GetVariance()), 0);
            }

            Vector3 targetDirection = targetCache.position - firePoint.position;

            if (Physics.Raycast(firePoint.position, targetDirection, out raycastHit, range))
            {
                Debug.DrawRay(firePoint.position, targetDirection, Color.red);
                PlayFireSound();
                reloadSystem.BulletSubtraction();
                SendDamage(raycastHit, bullet.GetDamage());
                CreateDecal(raycastHit);
                AddPhysicsImpact(raycastHit);
            }
        }
예제 #3
0
        private static void RayBulletGUI()
        {
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(5);
            GUILayout.Label(ContentProperties.BaseOptions, UEditorStyles.SectionHeaderLabel);
            GUILayout.Space(7);
            rayBullet.SetModel(EditorGUILayout.TextField(ContentProperties.Model, rayBullet.GetModel()));
            rayBullet.SetDamage(EditorGUILayout.IntField(ContentProperties.Damage, rayBullet.GetDamage()));
            rayBullet.SetVariance(EditorGUILayout.FloatField(ContentProperties.Variance, rayBullet.GetVariance()));
            rayBullet.SetNumberBullet(EditorGUILayout.IntField(ContentProperties.NumberBullet, rayBullet.GetNumberBullet()));
            rayBullet.SetDecalProperties(UEditor.ObjectField <DecalProperties>(ContentProperties.DecalProperties, rayBullet.GetDecalProperties(), false));

            GUILayout.Space(5);
            UEditor.HorizontalLine();
            GUILayout.Space(5);

            EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(rayBullet.GetModel()));
            if (UEditor.Button("Create", "Right", GUILayout.Width(70)))
            {
                string path = EditorUtility.SaveFilePanelInProject("Create new RayBullet", rayBullet.GetModel(), "", "");
                if (!string.IsNullOrEmpty(path))
                {
                    string name = System.IO.Path.GetFileName(path);
                    path = path.Replace(name, "");
                    ScriptableObjectUtility.CreateAsset(rayBullet, path, name);
                    CreateInstances();
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.Space(5);
            GUILayout.EndVertical();
        }