Posts

Showing posts from November, 2020

Unity Script Example

Image
    using UnityEngine; public class BoxieMotion : MonoBehaviour { Rigidbody myBody; public Rigidbody CappyBody; public Material cappyColor; public float xForce = 300; public float yForce = 300; // Start is called before the first frame update void Start() { myBody = this.GetComponent<Rigidbody>(); cappyColor.SetColor("_Color",Color.white); } // Update is called once per frame void Update() { if (Input.GetKeyDown("space")) { myBody.AddForce(xForce,yForce,0); } } private void OnCollisionEnter(Collision collision) { if (collision.gameObject.name == "Sphero") { Debug.Log("COLLIDED"); CappyBody.AddForce(0, 300, 0); cappyColor.SetColor("_Color", Color.yellow); } } }