Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created April 8, 2025 08:52
Show Gist options
  • Select an option

  • Save todorok1/b66807b0b6406f9e409df903582e44b6 to your computer and use it in GitHub Desktop.

Select an option

Save todorok1/b66807b0b6406f9e409df903582e44b6 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第64回 戦闘関連のスプライトを制御するクラス
/// <summary>
/// 背景と敵キャラクターの位置をカメラに合わせて設定します。
/// </summary>
public void SetSpritePosition()
{
if (_mainCamera == null)
{
_mainCamera = Camera.main;
}
var cameraPos = _mainCamera.transform.position;
var newPosition = new Vector3(cameraPos.x, cameraPos.y, 0);
var backgroundPosOffset = new Vector3(0, 0, 0);
_backgroundRenderer.transform.position = newPosition + backgroundPosOffset;
var enemyPosOffset = new Vector3(0, -0.5f, 0);
_enenyRenderer.transform.position = newPosition + enemyPosOffset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment