Exemplo n.º 1
0
        // Use this for initialization
        void Start()
        {
            var source = GetComponent <AudioSource>();

            _block = transform.Find("block");
            _deactivatedBlockPos = Vector3.zero;
            _activatedBlockPos   = _deactivatedBlockPos + Vector3.forward * activatedDepth;
            var lastClickTime = Time.time;

            if (Type != BlockType.Walkable)
            {
                GetComponentInChildren <IClickable>().OnClicked += () =>
                {
                    if (Clickable && Time.time - lastClickTime > 0.1f)
                    {
                        lastClickTime = Time.time;
                        Activated     = !Activated;
                        source.PlayOneShot(Activated ? ClickDownClip : ClickUpClip);
                        ToggleActivationWithEffect(Activated);
                        Board.AlertClick(this);
                        StartCoroutine(Move(Activated));
                    }
                }
            }
            ;
        }

        void SetMaterial(bool activated)
        {
            transform.Find("block").Find("default").GetComponent <Renderer>().material = activated ? OnMaterial : OffMaterial;
        }