示例#1
0
    public void OnKillObject(Character character)
    {
        character._health -= this._attackDamage;

        print("Attacking!");
        if (character._health == 0)
        {
            character.OnDeath();
            character.transform.localRotation = Quaternion.Euler(90, character.transform.localRotation.y, character.transform.localRotation.z);
            // character.transform.position = new Vector3(character.transform.position.x, -0.25f, character.transform.position.z);
        }
        else if (character._health < 0)
        {
            print("More dead");
            character._health = 0;
        }

        if (this.gameObject.layer == LayerMask.NameToLayer("Plant"))
        {
            if (character._health == 0)
            {
                PlantBehaviour pb = this.GetComponent <PlantBehaviour>();
                if (pb)
                {
                    pb.OnEat(character.GetComponentInParent <PossibleFood>());
                }
            }
        }
    }
示例#2
0
 void Start()
 {
     _actualPlant    = GameObject.Find("Test Hole").GetComponent <PlantBehaviour>();
     _MasterFlower   = GameObject.FindGameObjectWithTag("MasterFlower").GetComponent <Transform>();
     _masterFlowerGO = GameObject.FindGameObjectWithTag("MasterFlower").GetComponent <SpriteRenderer>();
     _spawner        = GameObject.FindGameObjectWithTag("Spawner").GetComponent <SpawnerBehaviour>();
     BuySoil(_actualPlant);
     _plantCost           = 10;
     _textColor           = _messages.color;
     _messageCanvasColor  = new Color(0, 0, 0, 0.6f);
     _messageCanvas.color = new Color(0, 0, 0, 0);
     _theEnd.SetActive(false);
 }
示例#3
0
    private void OnTriggerStay2D(Collider2D other)
    {
        Debug.Log(other.name);
        if (other.gameObject.CompareTag("Hole"))
        {
            if (Input.GetMouseButtonDown(0))
            {
                _plantLocal = other.GetComponent <PlantBehaviour>();
                if (_plantLocal._isActive == true)
                {
                    if (_plantLocal._spawnedBug == true)
                    {
                        //Debug.Log("nice try");
                        _plantLocal.KillBug();
                    }
                    else
                    if (_ID != -1 && _plantLocal._haveAPlantOn == false)
                    {
                        _plantLocal.NewPlants(_ID);
                        _ID                 = -1;
                        _buySeed.id         = _ID;
                        _childSprite.sprite = null;
                    }
                    else
                    {
                        _plantLocal.RemovePlant();
                    }
                }
                else
                {
                    _gm.BuySoil(_plantLocal);
                }
            }
        }

        if (other.gameObject.CompareTag("Enemy"))
        {
            _enemyKilled = other.GetComponent <EnemyBehaviour>();

            if (Input.GetMouseButtonDown(0))
            {
                _enemyKilled.TakeDamage(_actualDamage);
            }
        }
    }
示例#4
0
    public void BuySoil(PlantBehaviour p)
    {
        _actualPlant = p;
        if (collectedMoney >= _plantCost)//check if the player has enough money
        {
            collectedMoney = collectedMoney - _plantCost;
            _plantCost     = _plantCost + 5;

            //_actualPlant = _Plants[_nextBuy].GetComponent<PlantBehaviour>(); para que carajo hice esto?
            _actualPlant._isActive = true;
            //_nextBuy++;
            AudioSource.PlayClipAtPoint(_buyLandSound, transform.position);
        }
        else
        {
            _actualPlant.ChangeText("You dont have enough money" + "\n" + "Cost :" + _plantCost);
            Debug.Log("No tenes plata amiguito");
        }
    }
示例#5
0
文件: GameUI.cs 项目: MrTroyD/FeedMeh
 public void SetUpPlant(PlantBehaviour plant)
 {
     this._plant = plant;
 }
示例#6
0
 void Start()
 {
     starPos        = transform.position;
     plantBehaviour = FindObjectOfType <PlantBehaviour>();
 }
    //EAT* are the same expect for different object types
    //Could have made 1 object but decided to go with 2
    //Esp as the target type is already known.
    void EatPlant(PlantBehaviour plant)
    {
        float maxFood = plant.StealEnergy(eatSize);
        maxFood = maxFood / eatEffeciency;

        energy += maxFood;
        hunger += maxFood;
    }
示例#8
0
 private PlantBehaviour ChoosePrefab(PlantBehaviour[] prefabs) {
     return prefabs[Random.Range(0, prefabs.Length)];
 }
示例#9
0
    private bool PlacePlant(Vector2 sample, PlantBehaviour[] selectedPrefabs) {
        // get sound manager
        if (soundManager == null) {
            soundManager = FindObjectOfType<SoundManager>();
        }

        Vector3 pos = new Vector3(sample.x, height / 2f, sample.y);
        Vector3 worldPos = transform.TransformPoint(pos);

        RaycastHit hit;
        if (Physics.Raycast(worldPos, -transform.up, out hit, height, layerMask)) {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Ground") &&
                Vector3.Angle(transform.up, hit.normal) <= maxAngle) {
                Vector3 position = worldPos + hit.distance * -transform.up;

                worldSpaceSamples.Add(position);

                PlantBehaviour plant = (PlantBehaviour)Instantiate(ChoosePrefab(selectedPrefabs), position, Quaternion.identity);
                plant.transform.parent = transform;
                plant.SetNormal(hit.normal);
                plant.SoundManager = soundManager;

                plants.Add(plant);
                return true;
            }

            if (extraLogging) { Debug.Log("Raycast hit non-ground at " + worldPos); }
        } else if (extraLogging) { Debug.Log("Raycast missed at" + worldPos); }

        return false;
    }
示例#10
0
	private void GeneratePlants(PlantBehaviour[] selectedPrefabs, List<Vector2> externalSamples) {
        PoissonDiskSampler sampler = new PoissonDiskSampler(radius, minDist);
        int sampleCount = sampler.generateSamples(delegate(Vector2 s) { return PlacePlant(s, selectedPrefabs); }, externalSamples);

        if (extraLogging) { Debug.Log("Sample count: " + sampleCount); }

        // force a single plant
        if (sampleCount == 0) {
            if (minOnePlant) {
                PlacePlant(Vector2.zero, selectedPrefabs);
            } else {
                Debug.LogError("Failed to create plants: " + name + " in " + transform.parent.name);
            }
        }
	}