Exemplo n.º 1
0
	void SpawnAsteroid (Vector3 spawnModifier, Vector3 impactForce)
	{
		// Obtain a random prefab
		GameObject asteroid = RandomPrefab();
		if (asteroid)
		{
			// Instantiate the asteroid
			asteroid = (GameObject) Network.Instantiate (asteroid, transform.position + spawnModifier, transform.rotation, 0);
			
			// Add the impact force to keep the asteroid moving
			asteroid.rigidbody.velocity = rigidbody.velocity * m_velocityToMaintain;
			asteroid.rigidbody.AddForce (impactForce);
			
			// Scale the asteroid correctly
			AsteroidScript script = asteroid.GetComponent<AsteroidScript>();
			if (script)
			{
				script.TellToPropagateScaleAndMass (transform.localScale / m_splittingFragments, rigidbody.mass / m_splittingFragments);
                script.DelayedVelocitySync (Time.fixedDeltaTime);
                script.isFirstAsteroid = false;
			}
		}
		
		else
		{
			Debug.LogError ("AsteroidScript couldn't generate a random prefab for splitting.");
		}
	}
Exemplo n.º 2
0
    // Asteroids need to sync their velocity over the network after waiting for a FixedUpdate() call
    void SyncAsteroid(Rigidbody asteroid)
    {
        AsteroidScript script = asteroid.GetComponent <AsteroidScript>();

        if (script)
        {
            // Wait one FixedUpdate frame to sync the asteroids
            script.DelayedVelocitySync(Time.fixedDeltaTime);
        }
    }