public void OnTriggerStay2D(Collider2D other) { //print ("OnTriggerStay2D:" + other.ToString ()); ColorModel colorModelOther = other.GetComponent <ColorModel>(); if (!colorModelOther) { return; } Color crThis = _colorModel.GetDispColor(); Color crOther = colorModelOther.GetDispColor(); float colorDelta = 0.0f; colorDelta += Mathf.Abs(crThis.r - crOther.r); colorDelta += Mathf.Abs(crThis.g - crOther.g); colorDelta += Mathf.Abs(crThis.b - crOther.b); colorDelta /= 3.0f; // 0~1的数值范围 // 力的方向 Vector3 posThis = transform.position; Vector3 posOther = other.transform.position; Vector3 thisToOther = posOther - posThis; Vector3 forceDir = thisToOther.normalized; // 力的大小 float forceMag = _ForceMulitiplier * colorDelta; Vector3 force = forceMag * forceDir; Rigidbody2D rb = GetComponent <Rigidbody2D> (); rb.AddForce(force); }
void Update() { Color cr = _colorModel.GetDispColor(); SpriteRenderer spr = GetComponent <SpriteRenderer> (); spr.color = cr; }
// Update is called once per frame void Update() { Color cr = _colorModel.GetDispColor(); TrailRenderer tr = GetComponent <TrailRenderer> (); tr.startColor = cr; Color cr2 = cr; cr2.a = 0.0f; tr.endColor = cr2; }