Advertisement
Guest User

Unity Interface test

a guest
Apr 18th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public interface IMyInterface
  5. {
  6.     string MyString { get; set; }
  7. }
  8.  
  9. public class InterfaceTest : MonoBehaviour, IMyInterface
  10. {
  11.     private string _myString = "";
  12.     public string MyString
  13.     {
  14.         get
  15.         {
  16.             return _myString;
  17.         }
  18.         set
  19.         {
  20.             _myString = value;
  21.         }
  22.     }
  23.  
  24.     private void Start()
  25.     {
  26.         IMyInterface myInterface = GetComponent<IMyInterface>();
  27.         myInterface.MyString = "Test";
  28.         Debug.Log(string.Format("Interface property string : {0}, local property : {1}", myInterface.MyString, MyString));
  29.     }
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement