public bool BeginTow(BasicCrateController crate_) { if (null == crate && Input.GetKey(Release) || Input.GetKeyDown(Release)) { crate = crate_; return(true); } else { return(false); } }
private void TriggerAction(Collider coll, bool enter) { if (coll.isTrigger && null != coll.rigidbody) { GameObject go = coll.rigidbody.gameObject; BasicCrateController crate = go.GetComponent <BasicCrateController>(); if (null != crate) { if (enter) { Crates.Add(crate); } else { Crates.Remove(crate); } } } }
// Update is called once per frame void Update() { if (GameManager.Instance.GameRunning) { maxVelocitySquared = maxVelocity * maxVelocity; Vector3 impulse = Vector3.zero; // Locomotion if (Input.GetKey(Up)) { impulse.z = 1; } else if (Input.GetKey(Down)) { impulse.z = -1; } if (Input.GetKey(Left)) { impulse.x = -1; } else if (Input.GetKey(Right)) { impulse.x = 1; } impulse.Normalize(); if (null != crate) { impulse *= impulseMagnitude - crate.GetDrag(); } else { impulse *= impulseMagnitude; } rb.velocity += impulse; if (rb.velocity.sqrMagnitude > maxVelocitySquared) { Vector3 clampedVelocity = rb.velocity.normalized * maxVelocity; rb.velocity = clampedVelocity; } // Crate control if (Input.GetKeyUp(Release) && null != crate) { crate.Owner = null; crate = null; } if (crate != null && crate.Owner != this) { crate = null; } // Align self Vector3 facing = rb.velocity.normalized; if (facing.sqrMagnitude > 0.1f) { transform.forward = facing; } } }