Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Make child unaffected by parents rotation Unity

private float _rotation;
private Quaternion _originalRotation;
// set public to pass child reference in Unity Editor
public Canvas UIrotation;

    // Start is called before the first frame update
    void Start()
	{
    	// save child rotation values
  		_originalRotation = UIrotation.transform.rotation;
  		_rotation = transform.rotation.y;
	}

	private void OnMouseOver()
    {
    	// rotation of parent
        if (Input.GetKeyDown(KeyCode.Space))
        {
        	// parent rotate
            transform.Rotate(new Vector3(0, _rotation - 90, 0));
            // child rotate back to original without the need of update func 
            UIrotation.transform.rotation = _originalRotation;
        }
    }
 
PREVIOUS NEXT
Tagged: #Make #child #unaffected #parents #rotation #Unity
ADD COMMENT
Topic
Name
1+2 =