Plus de flexibilité, moins de code - un développement plus productif.
Unity3D — , 8 — , , -. , Unity -, , .
, , , - — , . - 24 72 , — , GitHub Game Off, .
-, C++ ( , ), , : — .
— (, , ) — :
: , .
: , .
Unity : Unity, .
, Unity3D .
: Unity 3D Technologies ( ).
1.
— . Unity .
— [Serializable] . — Unity:
[Serializable]
public struct PlayerStats
{
public int movementSpeed;
public int hitPoints;
public bool hasHealthPotion;
}
, , .
: , , — , .
public enum PlayerType
{
ARCHER, KNIGHT
}
[Serializable]
public struct PlayerStats
{
public int movementSpeed;
public int hitPoints;
public bool hasHealthPotion;
public Sprite face;
public PlayerType type;
}
, Unity — .
2. RequireComponent
— . , , , Rigidbody . — RequireComponent.
:
.
.
, .
RequireComponent :
[RequireComponent(typeof(Rigidbody))]
public class PlayerScript : MonoBehaviour
{
Rigidbody rigidbody;
void Awake()
{
rigidbody = GetComponent<Rigidbody>();
}
}
. Awake Start, .
. , RequireComponent . , — .
, , null, — , .
3.
, , : Unity . Unity , , , , .
, — .
OnClick: , , .
, , onClick Unity, . : — ( setActive(true) ), — ( play() ) Animator — ( setTrigger() ). — .
. . . , . : — , .
4. Unity
Unity UnityEvent, OnClick Unity. UnityEvent, , , OnClick:
, , UnityEvent . , UnityEvent Invoke:
using UnityEngine;
using UnityEngine.Events;
public class CallEventsScript : MonoBehaviour
{
public UnityEvent eventsToBeCalled;
public void CallEvents()
{
eventsToBeCalled.Invoke();
}
}
CallEvents UnityEvent. , , . — .
UnityEvent , , , Awake, Start, OnEnable, OnDisable . . , , Start, — .
— , : , . UnityEvent:
[RequireComponent(typeof(Collider))]
public class TriggerBoxScript : MonoBehaviour
{
public UnityEvent eventsToBeCalledOnCollision;
public List<string> objectsTagToActivate;
private void OnCollisionEnter(Collision other)
{
if (OtherHasWantedTag(other.gameObject))
{
InvokeEvents();
}
}
private void OnTriggerEnter(Collider other)
{
if (OtherHasWantedTag(other.gameObject))
{
InvokeEvents();
}
}
private bool OtherHasWantedTag(GameObject other)
{
var found = objectsTagToActivate.Find(other.CompareTag);
return found != null;
}
private void InvokeEvents()
{
eventsToBeCalledOnCollision.Invoke();
}
}
, ( OnTriggerEnter, OnCollisionEnter). , .
, . , «Player» — , . : , , , . .
, — Unity. — .
(OnClick UnityEvent) ( ) ( ).
, , : . , , , . Unity, .
, — , , . , , .
.
Alconost.
Alconost , 70 . - , , API, , 24/7, .
— , , , , , , , Google Play App Store.