コード例 #1
0
 public void OnBreak()
 {
     if (destroyedClip != null)
     {
         audioSourceMultichannel.GetChannel().PlayOneShot(destroyedClip);
     }
     isPlaced = true;
     Placed?.Invoke(false, transform.position);
     rigidbody2D.mass        = 10;
     snapOpen                = false;
     sprite.enabled          = false;
     breakingSprite.enabled  = false;
     brokenSprite.enabled    = true;
     highlightSprite.enabled = false;
     isHeld = false;
     placedTrigger.active         = false;
     placedTrigger.pickableObject = null;
     placedTrigger.canBePlaced    = false;
     brokeEffect.SetActive(true);
     brokeEffect.GetComponent <ParticleSystem>().Play();
     health = 0;
     Fallen?.Invoke();
     Broken?.Invoke();
     pickableTrigger.enabled = false;
     StartCoroutine(FadingOutBroken());
 }
コード例 #2
0
    IEnumerator CheckIfFalling()
    {
        while (this.transform.position.y > YCoordTreshold)
        {
            yield return(_updateWait);
        }

        Fallen?.Invoke();
    }
コード例 #3
0
    IEnumerator CheckIfFalling()
    {
        while (true)
        {
            if (this.transform.position.y < YCoordTreshold)
            {
                Fallen?.Invoke();
                break;
            }

            yield return(_updateWait);
        }
    }
コード例 #4
0
    private void Awake()
    {
        inputAction = new InputActions();
        inputAction.PlayerControls.Move.performed += ctx => movementInput = ctx.ReadValue <Vector2>();
        cf  = GetComponent <ConfigurableJoint>();
        jtd = GetComponent <JointTargetDisabler>();
        //inputAction.PlayerControls.Tackle.performed += ctx => tackle = ctx.ReadValue<float>();

        //set joint drive values
        jd  = new JointDrive();
        jd0 = new JointDrive();
        jd.positionSpring     = 10000;
        jd.positionDamper     = 200;
        jd.maximumForce       = 10000;
        jd0.positionDamper    = 0;
        jd0.positionSpring    = 0;
        jd0.maximumForce      = 0;
        jdGrad.positionDamper = 200;
        jdGrad.positionSpring = 10000;
        jdGrad.maximumForce   = 10000;
        myCollider            = GetComponent <Collider>();
        myRigidbody           = GetComponent <Rigidbody>();

        //disable collisions with controller collider and self
        foreach (Collider d in gameObject.GetComponentsInChildren <Collider>())
        {
            Physics.IgnoreCollision(myCollider, d);
        }

        camera          = GameObject.FindGameObjectWithTag("MainCamera");
        stateMachine    = new StateMachine();
        standingUpState = gameObject.AddComponent <StandingUp>();
        standingUpState.Initialize(this, stateMachine, "StandingUp");
        idleState = gameObject.AddComponent <Idle>();
        idleState.Initialize(this, stateMachine, "Idle");
        tacklingState = gameObject.AddComponent <Tackling>();
        tacklingState.Initialize(this, stateMachine, "Tackling");
        recoveringState = gameObject.AddComponent <Recovering>();;
        recoveringState.Initialize(this, stateMachine, "Recovering");
        movingState = gameObject.AddComponent <Moving>();;
        movingState.Initialize(this, stateMachine, "Moving");
        fallenState = gameObject.AddComponent <Fallen>();
        fallenState.Initialize(this, stateMachine, "Fallen");
        stateMachine.Initialize(idleState);
    }