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() != null);
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
27  void Awake(){
28   spriteRenderer = GetComponent ();
29  }
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 ().velocity;
76     bounce.y = 0f;
77     collision.transform.GetComponent ().velocity = bounce;
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(true);
31             for (int i = 0; i < fontTransforms.Length; i++)
32             {
33                 if (fontTransforms[i].gameObject.GetComponent() != null)
34                 {
35                     fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
36                     fontTransforms[i].gameObject.GetComponent().sortingLayerName = "GUI";
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(true);
46             for (int i = 0; i < fontTransforms.Length; i++)
47             {
48
49                 if (fontTransforms[i].gameObject.GetComponent() != null)
50                 {
51                     fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
52                     fontTransforms[i].gameObject.GetComponent().sortingLayerName = "GUI";
53                 }
54             }
55
56             BitmapFont bitmapFont2 = new BitmapFont(bitmapFont, label2);
57             bitmapFont2.setText(line2, 0, 15);
58             Transform[] fontTransforms2 = label2.GetComponentsInChildren(true);
59             for (int i = 0; i < fontTransforms2.Length; i++)
60             {
61                 if (fontTransforms2[i].gameObject.GetComponent() != null)
62                 {
63                     fontTransforms2[i].gameObject.layer = LayerMask.NameToLayer("GUI");
64                     fontTransforms2[i].gameObject.GetComponent().sortingLayerName = "GUI";
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().color = new Color(0.5f, 0.5f, 0.5f, 1);
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().color = new Color(1, 1, 1, 1);
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().hideGuide();
43             }
44             else
45             {
46                 guideObject.GetComponent().sprite = guides[guideIndex];
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().color = new Color(0.5f, 0.5f, 0.5f, 1);
23             SoundManager.playButtonSound();
24         }

SpriteRenderer 145 lượt xem

Gõ tìm kiếm nhanh...