private void SpawnScrap() { float speed = speedRange.GetRandomValue(); float angle = NihilRandom.Float(45, 135); Vector3 direction = new Vector3(Mathf.Cos(Mathf.Deg2Rad * angle), Mathf.Sin(Mathf.Deg2Rad * angle)); GameObject scrapInstance = Instantiate<GameObject>(scrapPrefab, transform.position, Quaternion.identity); Rigidbody2D scrapBody = scrapInstance.GetComponent<Rigidbody2D>(); ScrapInactive script = scrapInstance.GetComponent<ScrapInactive>(); script.Init(character, scrapGround, scrapDistanceThreshold, scrapAcceleration); scrapBody.velocity = direction.normalized * speed; }
private void SpawnScrap() { float speed = speedRange.GetRandomValue(); float angle = NihilRandom.Float(45, 135); Vector3 direction = new Vector3(Mathf.Cos(Mathf.Deg2Rad * angle), Mathf.Sin(Mathf.Deg2Rad * angle)); direction.Normalize(); Quaternion rotation = Quaternion.Euler(0, 0, angle); GameObject scrapInstance = Instantiate<GameObject>(scrapPrefab, transform.position, rotation); Rigidbody2D scrapBody = scrapInstance.GetComponent<Rigidbody2D>(); scrapBody.velocity = direction * speed; }