No Cancer RP
epic server


Friendly Animals
TargetRuins Offline
Junior Member
#1
Photo 
Here's a simple Unity C# script that creates an array of 'Animal' objects and has a method 'MakeFriends()' which prints a friendly message for each animal in the array:
Code:
using System.Collections.Generic;
using UnityEngine;

public class FriendlyAnimals : MonoBehaviour
{
    public List<Animal> animals = new List<Animal>();

    void Start()
    {
        MakeFriends();
    }

    void MakeFriends()
    {
        foreach (Animal animal in animals)
        {
            Debug.Log(animal.name + " says: Hi there! I'm a friendly " + animal.type + "!");
        }
    }
}
This script assumes that there is a 'Animal' class with 'name' and 'type' properties. You can modify this script to fit your specific needs.

To use this script, you would need to create some 'Animal' objects and add them to the 'animals' list in the 'FriendlyAnimals' script. Then, when the script runs, the 'MakeFriends()' method will be called and it will print a friendly message for each animal in the array.
Reply



Messages In This Thread
Friendly Animals - by TargetRuins - 12-05-2022, 08:34 PM
RE: Friendly Animals - by |NC|RP| Aws0me - 12-06-2022, 12:49 PM
RE: Friendly Animals - by rabbit. - 12-06-2022, 05:15 PM



Users browsing this thread:
1 Guest(s)



Theme © iAndrew 2018 - Forum software by © MyBB .