IEnumerator SendTo(Vector3 destination, BacteryProperties targetProps) { Rigidbody2D rigidBody = GetComponent <Rigidbody2D> (); rigidBody.drag *= 2f; Color final = props.colors [(int)targetProps.bacteryState]; Color initial = props.colors [(int)props.bacteryState]; float d1 = Vector3.Distance(transform.position, destination); float t = 0f; while ((Vector3.Distance(transform.position, destination) >= 0.05f) && t < 20f) { Vector3 direction = destination - transform.position; rigidBody.AddForce(direction); zVelocity += direction.z; zVelocity /= 30f; Vector3 newPos = transform.position + new Vector3(0f, 0f, zVelocity); transform.position = newPos; float d = Vector3.Distance(transform.position, destination); _renderer.GetPropertyBlock(_propBlock); _propBlock.SetColor("_EmissionColor", Color.Lerp(final, initial, d / d1)); _renderer.SetPropertyBlock(_propBlock); t += Time.deltaTime; yield return(null); } rigidBody.bodyType = RigidbodyType2D.Static; rigidBody.isKinematic = true; props = targetProps.Clone(); }
public void StartConjugate(Vector3 position, BacteryProperties targetProperties) { gameObject.layer = 11; BacteryProperties newProps = targetProperties.Clone(); props.bacteryState = BacteryState.moving; StartCoroutine(SendTo(position, targetProperties)); props.bacteryState = BacteryState.conjugating; Invoke("ConjugateBack", 3f); }
public void StickToWall() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 10f, (1 << 8) | (1 << 12))) { if (hit.collider.gameObject.layer == 8) { props.bacteryState = BacteryState.moving; gameObject.layer = 11; UpdateBacteryCount(); Debug.DrawRay(hit.point, hit.normal, Color.black); BacteryProperties targetProperties = props.Clone(); targetProperties.bacteryState = BacteryState.sticked; StartCoroutine(SendTo(hit.point, targetProperties)); } } }
public void Conjugate(int index, Vector3 targetPosition, BacteryProperties newBacteryProps) { Bactery2D b = bacteries [index].GetComponent <Bactery2D> (); b.StartConjugate(targetPosition, newBacteryProps); }
public static BacteryProperties Clone(this BacteryProperties props) { return(new BacteryProperties(props.divisionFrequency, props.bacteryState, props.colors)); }