Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How to instantiate object at fixed location?

$
0
0
Hey jeremy here! What I'm trying to do is instantiate an object at a random position within the radius of a sphere or cube! which I have done and works fine, the only trouble I seem to be having is when it spawns them in the scene it does not spawn them anywhere specific, just almost in the middle of the screen a little to the left!! But I need it to spawn from wherever I want, Im trying to do this with the code below but it seems to give me an error? var projectile : Rigidbody2D; var projectileSpawnPos : Transform; InvokeRepeating("LaunchProjectile", 1, 0.2); function LaunchProjectile () { var instance : Rigidbody2D = Instantiate(projectile); instance = Vector2(projectileSpawnPos.transform.position.x, projectileSpawnPos.transform.position.y); instance.velocity = Random.insideUnitSphere * 5; } Error: Assets/RandomSpawner.js(33,27): BCE0022: Cannot convert 'UnityEngine.Vector2' to 'UnityEngine.Rigidbody2D'.

Viewing all articles
Browse latest Browse all 171066

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>