前提・実現したいこと
現在RPGを作ろうとしていて、そのゲーム内の演出で勇者が生成した光のエネルギーを徐々に大きくして、正面の敵に向かって打ち出すようにしたいのです。それで、光の生成まではうまくいったのですが、徐々に大きくするという部分がうまくいきません。生成したオブジェクトを少しずつ大きくさせる方法をご教授いただきたくお願い申し上げますm(_ _;)m
該当のソースコード(C#)
/-------------------------------------------------------------
//BraveのRangedAtttack(遠隔攻撃)にて、光のエネルギーを発生させるスクリプト
-------------------------------------------------------------/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BraveShoot : MonoBehaviour
{
//生成する光エネルギーエフェクト
[SerializeField] private GameObject LightShoot;
//LightShot生成のためのTransform設定 [SerializeField] private Vector3 LightShootPosition = new Vector3(0f, 0f, 0f); [SerializeField] private Vector3 LightShootRotation = new Vector3(0f, 0f, 0f); [SerializeField] private Vector3 LightShootScale = new Vector3(1.0f, 1.0f, 1.0f); //ShotエフェクトのScale変更用 [SerializeField] private float LightSpeed; // 光エネルギー変化のスピード [SerializeField] private float maxSpeed; // 最高速度 [SerializeField] private Vector3 LightScale; // 光エネルギーの目標Scale private GameObject Energy; private float LightVelocity; // 光エネルギー変化用の現在の速度 private float startTime; // 開始時間 bool EnergyCharge = false; // Update is called once per frame void Update() { if (EnergyCharge == true) { //生成した光のエネルギーを徐々に大きくする。 var Scale_x = Mathf.SmoothDamp(LightShoot.transform.localScale.x, LightScale.x, ref LightVelocity, LightSpeed * Time.deltaTime, maxSpeed); var Scale_y = Mathf.SmoothDamp(LightShoot.transform.localScale.y, LightScale.y, ref LightVelocity, LightSpeed * Time.deltaTime, maxSpeed); var Scale_z = Mathf.SmoothDamp(LightShoot.transform.localScale.z, LightScale.z, ref LightVelocity, LightSpeed * Time.deltaTime, maxSpeed); LightShootScale.x = Scale_x; LightShootScale.y = Scale_y; LightShootScale.z = Scale_z; } } public void ShootEffect() { //エフェクトの生成する位置を設定。 Vector3 position = new Vector3(LightShootPosition.x, LightShootPosition.y, LightShootPosition.z); //エフェクトの生成する角度を設定。 Vector3 rotation = new Vector3(LightShootRotation.x, LightShootRotation.y, LightShootRotation.z); //上記の位置と角度でエフェクトを生成。 GameObject effectPlayer = (GameObject)Instantiate(LightShoot, position, Quaternion.Euler(rotation)); //生成したエフェクトを子オブジェクトにする。 effectPlayer.transform.parent = transform; //生成したエフェクトのScaleを「LightShotScale」に変更する effectPlayer.transform.localScale = LightShootScale; EnergyCharge = true; }
}
試したこと
Mathf.SmoothDampを使えば、値を徐々に変化させられるという記事を見つけたので、今回初めて大きさを変える部分に組み込んでみたのですが、うまくいっていないようです(?_?)
スクリプトの書き方が悪いのか、Inspector側の設定が悪いのかと悶々としております。
現在のInspectorをキャプチャして保存しましたので、貼らせていただきます。
どなたかこの件について解決案がございましたら、教えていただけると幸いです。
何卒よろしくお願いいたします (≧人≦)

回答1件
あなたの回答
tips
プレビュー