Inheritance: MonoBehaviour
Exemple #1
0
    void CreateObjective(Vector3 scale, float speed, string tag, Material mat)
    {
        GameObject objective = GameObject.CreatePrimitive(PrimitiveType.Sphere);

        objective.tag = tag;
        objective.transform.localScale = scale;
        objective.transform.SetParent(gameObject.transform);
        objective.transform.position = spawnPosition.position;

        Renderer renderer = objective.GetComponent <Renderer>();

        renderer.material = mat;

        Rigidbody objectiveRigidbody = objective.AddComponent <Rigidbody>();

        objectiveRigidbody.useGravity = true;
        objectiveRigidbody.AddForce(spawnPosition.forward * speed);

        DestroyOnCollision destroyScript = objective.AddComponent <DestroyOnCollision>();

        destroyScript.destroyTags = new List <string>()
        {
            "Player", "Background"
        };
    }
    protected override void OnUpdate()
    {
        // Assign values to local variables captured in your job here, so that it has
        // everything it needs to do its work when it runs later.
        // For example,
        //     float deltaTime = Time.DeltaTime;

        // This declares a new kind of job, which is a unit of work to do.
        // The job is declared as an Entities.ForEach with the target components as parameters,
        // meaning it will process all entities in the world that have both
        // Translation and Rotation components. Change it to process the component
        // types you want.


        var commandBuffer = _commandBufferSystem.CreateCommandBuffer();

        var a = new DestroyOnCollision()
        {
            CommandBuffer = commandBuffer
        };


        var handle = a.Schedule(_stepPhysicsWorld.Simulation, ref _physicsWorld.PhysicsWorld, Dependency);

        _commandBufferSystem.AddJobHandleForProducer(handle);
    }