Beispiel #1
0
 //this function assummes collided object always has BasePickable
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.layer == pickableLayerIndex)
     {
         var pickable = other.gameObject.GetComponent <DefaultPickable>();
         pickList.AddFirst(pickable);
         Debug.Log(string.Format("Item called {0} added to the pickables list", other.gameObject.name));
         onAnyHighLight.Raise(pickable.gameObject);
     }
 }
Beispiel #2
0
    /// <summary>
    /// Use only if you've already set up attack point if not use attack(transform)
    /// </summary>
    ///

    public void Attack()
    {
        //remember world space so have to also use transform.rot.euler.z
        var result = Physics2D.OverlapBoxAll((Vector2)originPoint.position, attackBounds, transform.rotation.eulerAngles.z, enemies);

        if (result.Length > 0)
        {
            Debug.LogFormat("Colided with {0}", result);
            foreach (Collider2D n in result)
            {
                if (!colList.Contains(n))
                {
                    var health = n.GetComponent <Mortal>();
                    if (health != null)
                    {
                        health.Damage(damage);
                        onThisHit(this.gameObject, health);
                        onAnyEnemyHit.Raise(n.gameObject);
                    }
                    else
                    {
                        Debug.LogFormat("Collided with {0} who does not have a health component", n.name);
                    }
                }
            }
            colList.AddRange(result);
        }
    }
Beispiel #3
0
 private void PickupCurrentShown()
 {
     if (currentState == pickerState.holding)
     {
         currentItem.onDeEquip(currentItemOldParent);
         currentItemOldParent = null;
         currentState         = 0;
         currentItem          = null;
         if (pickList.Count == 0)
         {
             return;
         }
     }
     if (pickList.Count != 0)
     {
         var selectedItem = pickList.First.Value.onPickup(this.gameObject);
         currentItemOldParent = selectedItem.transform.parent;
         selectedItem.transform.SetParent(weaponPoint, false);
         selectedItem.transform.localPosition = Vector3.zero;
         onAnyPickup.Raise(selectedItem);
         currentItem  = selectedItem.GetComponent <DefaultUsable>();
         currentState = pickerState.holding;
         selectedItem.transform.eulerAngles = Vector3.zero;
     }
 }
Beispiel #4
0
    public void PopulateSpecificContainer(ItemContainerTalker container)
    {
        if (container.hasItem)
        {
            container.DestroyItem();
        }
        int randomItem = Random.Range(0, libraryOfItems.Value.Count);

        Debug.Log("For container '" + container.name + "', Selecting item #" + randomItem + ": " + libraryOfItems.Value[randomItem].name);

        GameObject newItemGameObject = Instantiate(
            libraryOfItems.Value[randomItem],
            container.transform.position,
            container.transform.rotation,
            container.transform
            );

        CharacterCreatorItem newItem = newItemGameObject.GetComponent <CharacterCreatorItem>();

        if (newItem == null)
        {
            Debug.LogError("Item " + newItem.name + " did not contain a CharacterCreatorItem");
            return;
        }
        container.AddItem(newItem);
        container.descriptionViewer.UpdateDescriptionFromItem(newItem.gameObject);
        onItemSpawned.Raise(newItem.gameObject);
    }
Beispiel #5
0
        private void SetupCamera()
        {
            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            var          player  = players.First(p => p.GetComponent <NetworkedBehaviour>().IsLocalPlayer);

            changeCameraTarget.Raise(player);
        }
Beispiel #6
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         _onCollectedEvent.Raise();
         _collectablesAmount.Value += 1;
     }
 }
Beispiel #7
0
 private void ThrowWeapon()
 {
     if (currentState == pickerState.holding)
     {
         currentItem.gameObject.transform.SetParent(currentItemOldParent, true);
         currentItem.onThrow(weaponPoint);
         currentItemOldParent = null;
         onAnyThrow.Raise(currentItem.throwGO);
         currentState = 0;
     }
 }
Beispiel #8
0
    private void FixedUpdate()
    {
        currentMouseRay = cam.ScreenPointToRay(Input.mousePosition);
        if (Physics.SphereCast(currentMouseRay, targetingRadius.Value, out RaycastHit hit, maxDrawDistance, layMask))
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Enemies"))
            {
                onObjectSelected.Raise(hit.collider.gameObject);
                Debug.Log("Selected " + hit.collider.gameObject.name);
            }

            currentHitDistance = hit.distance;
        }
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        EditorGUILayout.HelpBox("This Game-Event passes along a GameObject", MessageType.Info, true);
        EditorGUILayout.HelpBox("The receiver of this event can potentially manipulate the GameObject that has been sent", MessageType.Warning, true);
        GameObjectGameEvent e = (GameObjectGameEvent)target;

        GUI.enabled       = Application.isPlaying;
        e.debugGameObject = (GameObject)EditorGUILayout.ObjectField("Debug Object", e.debugGameObject, typeof(GameObject), true);
        if (GUILayout.Button("Raise"))
        {
            e.Raise(e.debugGameObject);
            e.DebugMessage();
        }
    }
Beispiel #10
0
 private void OnTriggerEnter(Collider other)
 {
     _gameEvent?.Raise();
     _gameObjectGameEvent?.Raise(other.gameObject);
 }
Beispiel #11
0
 private void UseCurrentItem()
 {
     onAnyUse.Raise(currentItem.gameObject);
     currentItem.onPlayerUse();
 }
Beispiel #12
0
 private void cleanup()
 {
     onTomatoFinish.Raise(gameObject);
     MoveX.onComplete -= cleanup;
     Destroy(gameObject);
 }