GithubHelp home page GithubHelp logo

vaishnavi-saravanan / ex4.2-animal-feeding-phase-2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from archanasharikalharinarayanan/ex4.2-animal-feeding-phase-2

0.0 0.0 0.0 5.88 MB

License: BSD 3-Clause "New" or "Revised" License

C# 100.00%

ex4.2-animal-feeding-phase-2's Introduction

Ex4.2-Animal-Feeding-Phase-2

Aim:

To develop a animal feeding game-Phase-2 using unity.

Algorithm:

Step 1:

In the Hierarchy, create an Empty object called “SpawnManager”

Step 2:

Create a new script called “SpawnManager”, drag the script and attach it to the Spawn Manager in the hierarchy , and open it

Step 3:

Declare new public GameObject[ ] animalPrefabs;

Step 4:

In the inspector assign the size as 3 , for each element drag the animals from prefabs folder into the array

Step 5:

Double-click on one of the animal prefabs, then Add Component > Box Collider

Step 6:

Check the “Is Trigger” checkbox

Step 7:

Add a RigidBody component to the (banana)projectile and uncheck “use gravity”.

Step 8:

Create a new DetectCollisions.cs script, then drag the scripts and add it to each animal prefab and banana, then open it and check it.

Step 9:

For all the animal prefabs and food in th inspector (below the layer ) drop down the override option and choose apply all.

PROGRAM:

DEVELOPED BY: VAISHNAVI S
REG NO: 212222230165

SPAWN MANAGER:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManager : MonoBehaviour
{
    public GameObject[] animalPrefabs;
    private float spawnRangeX = 1;
    private float spawnPosZ = 1;
    private float startDelay = 2f;
    private float spawnInterval = 1.5f;

    void Start()
    {
        InvokeRepeating("SpawnRandomAnimal", startDelay, spawnInterval);
    }

    // Update is called once per frame
    void Update()
    {

    }

    void SpawnRandomAnimal()
    {
        int animalIndex = Random.Range(0, animalPrefabs.Length);
        Vector3 spawnPos = new Vector3(Random.Range(-spawnRangeX, spawnRangeX), 0, spawnPosZ);
        Instantiate(animalPrefabs[animalIndex], spawnPos, animalPrefabs[animalIndex].transform.rotation);
    }
}

DETECT COLLIDER:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DetectCollider : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }
    private void OnTriggerEnter(Collider other)
    {
        Destroy(other);
        Destroy(other.gameObject);
    }
}

OUTPUT:

324187107-2e515bd7-14fc-4fc4-99f2-c31fab69b7ad

RESULT:

Animal feeding game-Phase-2 using unity is developed successfully.

ex4.2-animal-feeding-phase-2's People

Contributors

vaishnavi-saravanan avatar archanasharikalharinarayanan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.