Renders a Sprite for 2D graphics.
no example available in JavaScript
//This example outputs Sliders that control the red green and blue elements of a sprite's color //Attach this to a GameObject and attach a SpriteRenderer component
using UnityEngine;
public class Example : MonoBehaviour { SpriteRenderer m_SpriteRenderer; //The Color to be assigned to the Renderer’s Material Color m_NewColor;
//These are the values that the Color Sliders return float m_Red, m_Blue, m_Green;
void Start() { //Fetch the SpriteRenderer from the GameObject m_SpriteRenderer = GetComponent<SpriteRenderer>(); //Set the GameObject's Color quickly to a set Color (blue) m_SpriteRenderer.color = Color.blue; }
void OnGUI() { //Use the Sliders to manipulate the RGB component of Color //Use the Label to identify the Slider GUI.Label(new Rect(0, 30, 50, 30), "Red: "); //Use the Slider to change amount of red in the Color m_Red = GUI.HorizontalSlider(new Rect(35, 25, 200, 30), m_Red, 0, 1);
//The Slider manipulates the amount of green in the GameObject GUI.Label(new Rect(0, 70, 50, 30), "Green: "); m_Green = GUI.HorizontalSlider(new Rect(35, 60, 200, 30), m_Green, 0, 1);
//This Slider decides the amount of blue in the GameObject GUI.Label(new Rect(0, 105, 50, 30), "Blue: "); m_Blue = GUI.HorizontalSlider(new Rect(35, 95, 200, 30), m_Blue, 0, 1);
//Set the Color to the values gained from the Sliders m_NewColor = new Color(m_Red, m_Green, m_Blue);
//Set the SpriteRenderer to the Color defined by the Sliders m_SpriteRenderer.color = m_NewColor; } }
adaptiveModeThreshold | The current threshold for Sprite Renderer tiling. |
color | Rendering color for the Sprite graphic. |
drawMode | The current draw mode of the Sprite Renderer. |
flipX | Flips the sprite on the X axis. |
flipY | Flips the sprite on the Y axis. |
maskInteraction | Specifies how the sprite interacts with the masks. |
size | Property to set/get the size to render when the SpriteRenderer.drawMode is set to SpriteDrawMode.NineSlice. |
sprite | The Sprite to render. |
tileMode | The current tile mode of the Sprite Renderer. |
gameObject | The game object this component is attached to. A component is always attached to a game object. |
tag | The tag of this game object. |
transform | The Transform attached to this GameObject. |
hideFlags | Should the object be hidden, saved with the scene or modifiable by the user? |
name | The name of the object. |
allowOcclusionWhenDynamic | Controls if dynamic occlusion culling should be performed for this renderer. |
bounds | The bounding volume of the renderer (Read Only). |
enabled | Makes the rendered 3D object visible if enabled. |
isPartOfStaticBatch | Has this renderer been statically batched with any other renderers? |
isVisible | Is this renderer visible in any camera? (Read Only) |
lightmapIndex | The index of the baked lightmap applied to this renderer. |
lightmapScaleOffset | The UV scale & offset used for a lightmap. |
lightProbeProxyVolumeOverride | If set, the Renderer will use the Light Probe Proxy Volume component attached to the source GameObject. |
lightProbeUsage | The light probe interpolation type. |
localToWorldMatrix | Matrix that transforms a point from local space into world space (Read Only). |
material | Returns the first instantiated Material assigned to the renderer. |
materials | Returns all the instantiated materials of this object. |
motionVectorGenerationMode | Specifies the mode for motion vector rendering. |
probeAnchor | If set, Renderer will use this Transform's position to find the light or reflection probe. |
realtimeLightmapIndex | The index of the realtime lightmap applied to this renderer. |
realtimeLightmapScaleOffset | The UV scale & offset used for a realtime lightmap. |
receiveShadows | Does this object receive shadows? |
reflectionProbeUsage | Should reflection probes be used for this Renderer? |
shadowCastingMode | Does this object cast shadows? |
sharedMaterial | The shared material of this object. |
sharedMaterials | All the shared materials of this object. |
sortingLayerID | Unique ID of the Renderer's sorting layer. |
sortingLayerName | Name of the Renderer's sorting layer. |
sortingOrder | Renderer's order within a sorting layer. |
worldToLocalMatrix | Matrix that transforms a point from world space into local space (Read Only). |
BroadcastMessage | Calls the method named methodName on every MonoBehaviour in this game object or any of its children. |
CompareTag | Is this game object tagged with tag ? |
GetComponent | Returns the component of Type type if the game object has one attached, null if it doesn't. |
GetComponentInChildren | Returns the component of Type type in the GameObject or any of its children using depth first search. |
GetComponentInParent | Returns the component of Type type in the GameObject or any of its parents. |
GetComponents | Returns all components of Type type in the GameObject. |
GetComponentsInChildren | Returns all components of Type type in the GameObject or any of its children. |
GetComponentsInParent | Returns all components of Type type in the GameObject or any of its parents. |
SendMessage | Calls the method named methodName on every MonoBehaviour in this game object. |
SendMessageUpwards | Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour. |
GetInstanceID | Returns the instance id of the object. |
ToString | Returns the name of the GameObject. |
GetClosestReflectionProbes | Returns an array of closest reflection probes with weights, weight shows how much influence the probe has on the renderer, this value is also used when blending between reflection probes occur. |
GetPropertyBlock | Get per-renderer material property block. |
SetPropertyBlock | Lets you add per-renderer material parameters without duplicating a material. |
Destroy | Removes a gameobject, component or asset. |
DestroyImmediate | Destroys the object obj immediately. You are strongly recommended to use Destroy instead. |
DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
FindObjectOfType | Returns the first active loaded object of Type type. |
FindObjectsOfType | Returns a list of all active loaded objects of Type type. |
Instantiate | Clones the object original and returns the clone. |
bool | Does the object exist? |
operator != | Compares if two objects refer to a different object. |
operator == | Compares two object references to see if they refer to the same object. |
OnBecameInvisible | OnBecameInvisible is called when the object is no longer visible by any camera. |
OnBecameVisible | OnBecameVisible is called when the object became visible by any camera. |