mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2026-01-06 11:50:56 +07:00
top-down сэмпл
This commit is contained in:
9
Assets/IsoTools/Examples/Scripts/Dragosha.meta
Normal file
9
Assets/IsoTools/Examples/Scripts/Dragosha.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0633b7c03325e42f99bb97e7a8b3b7b7
|
||||
folderAsset: yes
|
||||
timeCreated: 1477135354
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/IsoTools/Examples/Scripts/Dragosha/CloudController.cs
Normal file
47
Assets/IsoTools/Examples/Scripts/Dragosha/CloudController.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace IsoTools.Examples.Dragosha {
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
public class CloudController : MonoBehaviour {
|
||||
|
||||
public float minY = 8.0f;
|
||||
public float maxY = 12.0f;
|
||||
|
||||
public float minSpeed = 0.3f;
|
||||
public float maxSpeed = 1.0f;
|
||||
|
||||
float _speed = 0.0f;
|
||||
SpriteRenderer _sprRenderer = null;
|
||||
|
||||
void Start() {
|
||||
_sprRenderer = GetComponent<SpriteRenderer>();
|
||||
if ( !_sprRenderer ) {
|
||||
throw new UnityException("CloudController. SpriteRenderer component not found!");
|
||||
}
|
||||
Rewind(false);
|
||||
}
|
||||
|
||||
void Update() {
|
||||
var pos = transform.position;
|
||||
pos.x += _speed * Time.deltaTime;
|
||||
|
||||
var screen_pnt = Camera.main.WorldToScreenPoint(
|
||||
new Vector3(pos.x - _sprRenderer.bounds.size.x, pos.y, pos.z));
|
||||
if ( screen_pnt.x > Screen.width ) {
|
||||
Rewind(true);
|
||||
} else {
|
||||
transform.position = pos;
|
||||
}
|
||||
}
|
||||
|
||||
void Rewind(bool reset_position) {
|
||||
_speed = Random.Range(minSpeed, maxSpeed);
|
||||
if ( reset_position ) {
|
||||
transform.position = new Vector3(
|
||||
-_sprRenderer.bounds.size.x,
|
||||
Random.Range(minY, maxY),
|
||||
transform.position.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 749dbe219069a4160b4c39f82e027467
|
||||
timeCreated: 1477139194
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace IsoTools.Examples.Dragosha {
|
||||
[RequireComponent(typeof(IsoRigidbody))]
|
||||
public class PlayerController : MonoBehaviour {
|
||||
|
||||
public float speed = 1.0f;
|
||||
public SpriteRenderer sprite = null;
|
||||
|
||||
IsoObject _isoObject = null;
|
||||
IsoRigidbody _isoRigidbody = null;
|
||||
|
||||
void Start() {
|
||||
if ( !sprite ) {
|
||||
throw new UnityException("PlayerController. Sprite not found!");
|
||||
}
|
||||
_isoObject = GetComponent<IsoObject>();
|
||||
if ( !_isoObject ) {
|
||||
throw new UnityException("PlayerController. IsoObject component not found!");
|
||||
}
|
||||
_isoRigidbody = GetComponent<IsoRigidbody>();
|
||||
if ( !_isoRigidbody ) {
|
||||
throw new UnityException("PlayerController. IsoRigidbody component not found!");
|
||||
}
|
||||
}
|
||||
|
||||
void Update () {
|
||||
if ( Input.GetKey(KeyCode.LeftArrow) ) {
|
||||
var velocity = _isoRigidbody.velocity;
|
||||
velocity.x = -speed;
|
||||
sprite.flipX = true;
|
||||
_isoRigidbody.velocity = velocity;
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.RightArrow) ) {
|
||||
var velocity = _isoRigidbody.velocity;
|
||||
velocity.x = speed;
|
||||
sprite.flipX = false;
|
||||
_isoRigidbody.velocity = velocity;
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.DownArrow) ) {
|
||||
var velocity = _isoRigidbody.velocity;
|
||||
velocity.y = -speed;
|
||||
_isoRigidbody.velocity = velocity;
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.UpArrow) ) {
|
||||
var velocity = _isoRigidbody.velocity;
|
||||
velocity.y = speed;
|
||||
_isoRigidbody.velocity = velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0018b4f2ed0544a8da6a5c784de0b363
|
||||
timeCreated: 1477136889
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user