Skip to content

Instantly share code, notes, and snippets.

@maco1028
maco1028 / score.cs
Last active July 12, 2017 02:04
スコア加点処理 #unity
//コントローラー用(別々のスクリプト)
int score = 0;
GameObject scoreText;
public void AddScore(){
this.score += 10;
}
void Start () {
this.scoreText = GameObject.Find ("Score");
@maco1028
maco1028 / itween.cs
Last active July 12, 2017 01:38
iTween再生
bool ShootBool = false;
void Update () {
//タッチしたら再生されないようにする(連続再生させない)
if (Input.GetMouseButtonDown(0) && !ShootBool) {
ShootBool = true;
iTweenEvent.GetEvent(gameObject,"shoot").Play();
Debug.Log ("Shoot");
}
}//Update
@maco1028
maco1028 / animation.cs
Created July 11, 2017 05:05
アニメーション再生(レガシー)
// Use this for initialization
void Start ()
{
Animation anim = gameObject.GetComponent<Animation> ();
PlayAnimation (anim);
}
void PlayAnimation (Animation anim)
{
anim.Play ();
@maco1028
maco1028 / click.cs
Created July 10, 2017 22:17
クリックしたオブジェクトの取得
// 左クリックしたオブジェクトを取得する関数(3D)
public GameObject getClickObject() {
GameObject result = null;
// 左クリックされた場所のオブジェクトを取得
if(Input.GetMouseButtonDown(0)) {
   Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
   RaycastHit hit = new RaycastHit();
   if (Physics.Raycast(ray, out hit)){
     result = hit.collider.gameObject;
   }
@maco1028
maco1028 / RotateObject.cs
Last active June 6, 2018 13:25
回転 #unity
transform.Rotate(X * Time.deltaTime, Y * Time.deltaTime, Z * Time.deltaTime);
@maco1028
maco1028 / date.cs
Last active May 7, 2017 13:29
日付取得
// 現在時刻の取得
System.DateTime now = System.DateTime.Now;
int nowMonth;
int nowDay;
now = System.DateTime.Now;
nowMonth = now.Month;
nowDay = now.Day;
@maco1028
maco1028 / DoubleSide.cs
Created May 7, 2017 09:04
両面シェーダー
Shader "DoubleSide" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Cull off
@maco1028
maco1028 / script_onoff.cs
Created May 7, 2017 09:01
ScriptをON OFF
// ボタンの設定
function OnGUI () {
// バッググラウンドと名前設定
GUI.Box (Rect (10,10,100,90), "メニュー");
// ボタンの位置と名前設定
if (GUI.Button (Rect (20,40,80,20), "Script ON")) {
// ボタン押した時に実行したいもの
GetComponent(スクリプト名).enabled = true;
}
if (GUI.Button (Rect (20,70,80,20), "Script OFF")) {
@maco1028
maco1028 / hide_change.cs
Created May 7, 2017 08:52
表示非表示2
public GameObject[] Num_spline = new GameObject[10];
public bool parchk=true;
void Start () {
}
void Update () {
if (Input.GetMouseButtonDown(0)) {
@maco1028
maco1028 / unitymain.cs
Last active September 14, 2021 04:12
よく使うUnityスクリプト
1.現在のシーン名を判定
if(Application.loadedLevelName == "main"){
scene = true;
}else{
scene = false;
}
2.回転させる
this.transform.Rotate (new Vector3 (0, 0, 5 * Time.deltaTime));