【Unity】プログラム知識なしで塊魂を作ろう!
久しぶりにUnityを触りました。
誰でも簡単に塊魂っぽいゲームを作れるように動画にしてまとめてみました!
ブログの方ではテキストで掲示できるので、スクリプトのサンプルを置いておきます。
あくまでも、素人による素人のためのスクリプトです。
玄人から見たら無駄があるかもしれません。
FollowPlayer.cs
カメラをプレイヤーに追従させるスクリプト
カメラにつけて使用する
using UnityEngine;
using System.Collections;
public class FollowPlayer : MonoBehaviour
{
public Transform target;
private Vector3 offset;
void Start()
{
offset = GetComponent<Transform>().position - target.position;
}
void Update()
{
GetComponent<Transform>().position = target.position + offset;
}
}
Item.cs
アイテムをプレイヤーにくっつけるスクリプト
アイテムにつけて使用する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Item : MonoBehaviour
{
void OnTriggerEnter(Collider hit)
{
if (hit.CompareTag("Player"))
{
this.transform.parent = hit.gameObject.transform;
}
}
}
ScaleChanger.cs
アイテムを取るとプレイヤーの大きさを増やすスクリプト
プレイヤーにつけてしようする
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScaleChanger : MonoBehaviour
{
public float scale = 1.0f;
void OnTriggerEnter(Collider hit)
{
if (hit.CompareTag("Item"))
{
transform.localScale = new Vector3(scale + 0.1f, scale + 0.1f, scale + 0.1f);
}
}
}