Last active
December 30, 2020 22:14
-
-
Save hidsh/167b1b3061d25c02336e0ca3f35d1691 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
Transform t; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
t = transform; // transform はクラスなので t には transform への参照がコピーされる | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
t.position += Vector3.right; // 参照を変更しているのでコピー元に反映される → 動く | |
} | |
} |
This file contains hidden or 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
Vector3 v; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
v = transform.position; // position は構造体なので v には position の中身の値がコピーされる | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
v += Vector3.right; // vを変更して、positionが変更されることを期待しているがそうならない | |
// position は値型でコピーされているので v が変更されるだけで | |
// コピー元の position には反映されない → 動かない! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
C# の値型と参照型
値型
int
double
float
char
bool
構造体 <--!!!
参照型
string
class <--!!!
配列