Created
March 15, 2015 08:18
-
-
Save jake1256/6f6a6ebe69e38fd9ec65 to your computer and use it in GitHub Desktop.
【Unity】桜を咲かせてみた【初心者向け】 ref: http://qiita.com/kuuki_yomenaio/items/ea77a12834296645bc92
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CharacterMove : MonoBehaviour { | |
float forwardSpeed = 3.0f; | |
float backwardSpeed = 1.0f; | |
float rotateSpeed = 10.0f; | |
CharacterController characterController; | |
void Start () { | |
characterController = GetComponent<CharacterController>(); | |
} | |
void Update () { | |
float v = Input.GetAxis("Vertical"); | |
float h = Input.GetAxis("Horizontal"); | |
Vector3 velocity = new Vector3(0, 0, v); | |
velocity = transform.TransformDirection(velocity); | |
if (v > 0) { | |
velocity *= forwardSpeed; | |
} else if (v < 0) { | |
velocity *= backwardSpeed; | |
} | |
characterController.Move(velocity * Time.deltaTime); | |
transform.Rotate(0, h * rotateSpeed, 0); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class SakuraCreater : MonoBehaviour { | |
public GameObject flower; | |
public ParticleSystem sakuraSakuEffect; | |
public ParticleSystem sakuraTiruEffect; | |
// Use this for initialization | |
void Start () { | |
sakuraSakuEffect.Stop(); | |
sakuraTiruEffect.Stop(); | |
} | |
/// <summary> | |
/// BoxColliderのIsTriggerをONにしている際に、 | |
/// オブジェクトが範囲に入った際に呼ばれるイベント | |
/// </summary> | |
/// <param name="col">Col.</param> | |
void OnTriggerEnter(Collider col){ | |
for(int i = 0 ; i < 5 ; i++){ | |
createSakura(); | |
} | |
sakuraSakuEffect.Play(); | |
sakuraTiruEffect.Play(); | |
} | |
/// <summary> | |
/// 桜の花を一つ作成します。 | |
/// </summary> | |
/// <returns>The sakura.</returns> | |
private void createSakura(){ | |
Vector3 pos = this.gameObject.transform.position; | |
float x = Random.Range(-1.0f , 1.0f); | |
float y = Random.Range(1.0f , 2.0f); | |
float z = Random.Range(-1.0f , 1.0f); | |
pos.x += x; | |
pos.y += y; | |
pos.z += z; | |
GameObject obj = Instantiate(flower , pos , Quaternion.identity) as GameObject; | |
obj.transform.SetParent(this.gameObject.transform); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment