Exemple #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            targetObject = target as CustomPhysicsController;
            //base.OnInspectorGUI();


            EditorGUILayout.PropertyField(_rb);
            EditorGUILayout.PropertyField(_pushThanTakeDamage);
            if (targetObject._pushThanTakeDamage)
            {
                EditorGUILayout.PropertyField(_pushPowerOnTakenDamage);
            }

            EditorGUILayout.PropertyField(_movingType);
            switch ((CustomPhysicsType)_movingType.enumValueIndex)
            {
            case CustomPhysicsType.Basic:
                targetObject._movingType = CustomPhysicsType.Basic;
                EditorGUILayout.PropertyField(_needRotation);
                EditorGUILayout.PropertyField(_maxSpeedUsedForSumOFAxis);
                break;

            case CustomPhysicsType.BasicMovingToTarget:
                targetObject._movingType = CustomPhysicsType.BasicMovingToTarget;
                EditorGUILayout.PropertyField(_target);
                EditorGUILayout.PropertyField(_distanceToStop);
                EditorGUILayout.PropertyField(_needRotation);
                break;

            case CustomPhysicsType.Car:
                targetObject._movingType = CustomPhysicsType.Car;
                EditorGUILayout.PropertyField(_maxBackSpeed);
                EditorGUILayout.PropertyField(_rotateSpeed);
                break;
            }


            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(_maxSpeed);
            EditorGUILayout.PropertyField(_timeToMaxSpeed);
            EditorGUILayout.PropertyField(_timeToStopping);
            EditorGUILayout.PropertyField(_speedOfFadingPushPower);

            EditorGUILayout.PropertyField(_currSpeed);
            EditorGUILayout.PropertyField(_currSpeedVector);
            EditorGUILayout.PropertyField(_forwardVector);
            EditorGUILayout.PropertyField(_pushVector);
            serializedObject.ApplyModifiedProperties();



            if (UnityEditor.EditorApplication.isPlaying)
            {
                if (GUILayout.Button("Stop"))
                {
                    targetObject.RigidbodyReinitialize();
                }
            }
        }
Exemple #2
0
    /// <summary>
    /// Нанесение урона игроку
    /// </summary>
    /// <param name="playerGO">GameObject игрока</param>
    private void DamageToPlayer(GameObject playerGO)
    {
        //Если урон ненулевой и прошел таймаут для нанесения урона
        if (_damage != 0 && Time.time - _lastHit > _hitTimeoutOnStay)
        {
            //Наносим урон
            HealthController healthController = playerGO.GetComponent <HealthController>();
            if (healthController != null)
            {
                healthController.GetDamage(_damage);
            }

            //Толкаем, если нужно
            CustomPhysicsController customPhysicsController = playerGO.GetComponent <CustomPhysicsController>();
            if (customPhysicsController != null)
            {
                if (customPhysicsController.PushThanTakeDamage)
                {
                    customPhysicsController.AddPushOnHit(playerGO.transform.position - transform.position);
                }
            }

            //Фиксируем время нанесения урона
            _lastHit = Time.time;
        }
    }
    void OnCollisionEnter2D(Collision2D collision)
    {
        //Если урон не нулевой
        if (_damage != 0)
        {
            //Нанести урон, если у объекта есть компонент жизней
            HealthController healthController = collision.gameObject.GetComponent <HealthController>();
            if (healthController != null)
            {
                healthController.GetDamage(_damage);
            }

            //Толкаем, если нужно
            CustomPhysicsController customPhysicsController = collision.gameObject.GetComponent <CustomPhysicsController>();
            if (customPhysicsController != null)
            {
                customPhysicsController.AddExplosionPush((collision.gameObject.transform.position - transform.position) * 4);
            }
        }
    }