SpriteRenderer
How do I use Sprite Renderer
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: MoveByKeys.cs
Copy
26 public void Start()
27 {
28 //enabled = photonView.isMine;
29 this.isSprite = (GetComponent
30
31 this.body2d = GetComponent
32 this.body = GetComponent
33 }
File name: PlayerCtrl.cs
Copy
30 void Start () {
31 rb = GetComponent
32 sr = GetComponent
33 anim = GetComponent
34 }
File name: Structure.cs
Copy
46 void OnCollisionEnter2D(Collision2D collision){
47 if(collision.relativeVelocity.magnitude > damageCounter){
48 hitpoints -= Mathf.RoundToInt (collision.relativeVelocity.magnitude);
49 UpdateScoreStatus (Mathf.RoundToInt (collision.relativeVelocity.magnitude));
50 }
51
52
53 if (hitpoints <= 50) {
54 spriteRenderer.sprite = sprite [0];
55 if(counter == 2){
56 AudioManager ();
57 counter--;
58 }
59
60 }
61
62 if(hitpoints <= 30){
63 spriteRenderer.sprite = sprite [1];
64 if(counter == 1){
65 AudioManager ();
66 counter--;
67 }
68 }
69
70
71 if(hitpoints <= 0){
72 Destroyed ();
73
74 if(collision.gameObject.CompareTag("Player Bullet")){
75 bounce = collision.transform.GetComponent
76 bounce.y = 0f;
77 collision.transform.GetComponent
78 }
79 }
80 }
File name: DialogUnity.cs
Copy
26 public void setText(string oneline)
27 {
28 bitmapFont = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", label1);
29 bitmapFont.setText(oneline, 0, 15);
30 Transform[] fontTransforms = label1.GetComponentsInChildren
31 for (int i = 0; i < fontTransforms.Length; i++)
32 {
33 if (fontTransforms[i].gameObject.GetComponent
34 {
35 fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
36 fontTransforms[i].gameObject.GetComponent
37 }
38 }
39 }
File name: DialogUnity.cs
Copy
41 public void setText(string line1, string line2)
42 {
43 bitmapFont = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", label1);
44 bitmapFont.setText(line1, 0, 15);
45 Transform[] fontTransforms = label1.GetComponentsInChildren
46 for (int i = 0; i < fontTransforms.Length; i++)
47 {
48
49 if (fontTransforms[i].gameObject.GetComponent
50 {
51 fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
52 fontTransforms[i].gameObject.GetComponent
53 }
54 }
55
56 BitmapFont bitmapFont2 = new BitmapFont(bitmapFont, label2);
57 bitmapFont2.setText(line2, 0, 15);
58 Transform[] fontTransforms2 = label2.GetComponentsInChildren
59 for (int i = 0; i < fontTransforms2.Length; i++)
60 {
61 if (fontTransforms2[i].gameObject.GetComponent
62 {
63 fontTransforms2[i].gameObject.layer = LayerMask.NameToLayer("GUI");
64 fontTransforms2[i].gameObject.GetComponent
65 }
66 }
67 }
File name: NextGuideClickListener.cs
Copy
22 public override void OnTouchDown()
23 {
24 if (InputController.Name != InputNames.DIALOG) return;
25 base.OnTouchDown();
26 gameObject.GetComponent
27 SoundManager.playButtonSound();
28 }
File name: NextGuideClickListener.cs
Copy
29 public override void OnCheckUp()
30 {
31 if (InputController.Name != InputNames.DIALOG) return;
32 base.OnCheckUp();
33 gameObject.GetComponent
34 }
File name: NextGuideClickListener.cs
Copy
35 public override void OnTouchUp()
36 {
37 if (InputController.Name != InputNames.DIALOG) return;
38 base.OnTouchUp();
39 guideIndex++;
40 if (guideIndex == 4)
41 {
42 gameObject.transform.parent.gameObject.GetComponent
43 }
44 else
45 {
46 guideObject.GetComponent
47 }
48 }
File name: ButtonStartClickListener.cs
Copy
18 public override void OnTouchDown()
19 {
20 if (InputController.Name != InputNames.DIALOG) return;
21 base.OnTouchDown();
22 gameObject.GetComponent
23 SoundManager.playButtonSound();
24 }
SpriteRenderer 145 lượt xem
Gõ tìm kiếm nhanh...