Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity interfaces

// When you use an interface, you can use two diferent objects to perform one 
// action in common that executes diferently in each of theme.

Interface IDrivable {
	void Drive(); //just the sentence
    //....
}

// Examples of uses:

class Car1 : IDrivable
{ 
	void Drive() {
	//actions to drive the first Car
	}
}

class Car2 : IDrivable
{
	void Drive() {
	//actions to drive the second Car
	}
}

// In this example Car1 and Car2 are diferent classes and each of theme
// drives diferently, but can be used in something like this:

public IDrivable CarToDrive;
CarToDrive.Drive() // this executes Drive() in the selected car, no methers
					// what car is.
Comment

unity interface

//This code is in a seperate class

public interface ISomethingable<T>
{
	
	int RandomVar {get; set} // This is not needed, you can use any variable
    
	// need to be present in classes, which use this interface
    void Function(T Arg);

}

//This Code is in a seperate class

public class Thingy : MonoBehaviour, ISomethingable<T>
{

	public void Function(int Arg)
    {
    
    	Debug.Log(Arg);
    
    }

}

Comment

unity run all interfaces

 using System.Linq;   
 ...    
              var ss = FindObjectsOfType<MonoBehaviour>().OfType<IStats>();
              foreach (IStats s in ss) {
                  enemies.Add (s);
              }
Comment

PREVIOUS NEXT
Code Example
Csharp :: length of a string c# 
Csharp :: get key value from object c# 
Csharp :: creating a streamwiter file C# 
Csharp :: how to play multiple sound at once on c# windows form 
Csharp :: c# create tasks and wait all 
Csharp :: unity find gameobject with layer 
Csharp :: c# radio button checked 
Csharp :: unity call function on update once per second 
Csharp :: how to add headers to scripts in unity 
Csharp :: c# .net core memory cache 
Csharp :: unity switch 
Csharp :: minimize window windows forms application c# 
Csharp :: long number multiplication 
Csharp :: trim c# 
Csharp :: unity send post request json 
Csharp :: array sort C Sharp 
Csharp :: subtract days c# 
Csharp :: change scale of an object unity 
Csharp :: c# swap name in string 
Csharp :: rotate gameobject unity 
Csharp :: c# list.foreach 
Csharp :: c# how to print 
Csharp :: Kill System Process in C# 
Csharp :: c# next level script 
Csharp :: vb.net remove last comma from string 
Csharp :: c# yield keyword 
Csharp :: order 3 integers in c# 
Csharp :: C# Bitwise Right Shift 
Csharp :: unity position ui element 
Csharp :: string to array c# 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =