예제 #1
0
    private List<Vector3[]> forces; // For drawing force gizmos

    /// <summary>
    /// Provides initialization.
    /// </summary>
    private void Start()
    {
        forces = new List<Vector3[]>(); // For drawing force gizmos

        //Get the waveControllerScript
        GameObject gameController = GameObject.FindGameObjectWithTag("WaveManager");
        waveScript = gameController.GetComponent<WaveBehavior>();

        // Store original rotation and position
        var originalRotation = transform.rotation;
        var originalPosition = transform.position;
        transform.rotation = Quaternion.identity;
        transform.position = Vector3.zero;

        // The object must have a collider
        if (GetComponent<Collider>() == null)
        {
            gameObject.AddComponent<MeshCollider>();
            Debug.LogWarning(string.Format("[Buoyancy.cs] Object \"{0}\" had no collider. MeshCollider has been added.", name));
        }
        isMeshCollider = GetComponent<MeshCollider>() != null;

        var bounds = GetComponent<Collider>().bounds;
        if (bounds.size.x < bounds.size.y)
        {
            voxelHalfHeight = bounds.size.x;
        }
        else
        {
            voxelHalfHeight = bounds.size.y;
        }
        if (bounds.size.z < voxelHalfHeight)
        {
            voxelHalfHeight = bounds.size.z;
        }
        voxelHalfHeight /= 2 * slicesPerAxis;

        // The object must have a RidigBody
        if (GetComponent<Rigidbody>() == null)
        {
            gameObject.AddComponent<Rigidbody>();
            Debug.LogWarning(string.Format("[Buoyancy.cs] Object \"{0}\" had no Rigidbody. Rigidbody has been added.", name));
        }
        GetComponent<Rigidbody>().centerOfMass = new Vector3(0, -bounds.extents.y * 0f, 0) + transform.InverseTransformPoint(bounds.center);

        voxels = SliceIntoVoxels(isMeshCollider && isConcave);

        // Restore original rotation and position
        transform.rotation = originalRotation;
        transform.position = originalPosition;

        float volume = GetComponent<Rigidbody>().mass / density;

        WeldPoints(voxels, voxelsLimit);

        float archimedesForceMagnitude = WATER_DENSITY * Mathf.Abs(Physics.gravity.y) * volume;
        localArchimedesForce = new Vector3(0, archimedesForceMagnitude, 0) / voxels.Count;

        //Debug.Log(string.Format("[Buoyancy.cs] Name=\"{0}\" volume={1:0.0}, mass={2:0.0}, density={3:0.0}", name, volume, GetComponent<Rigidbody>().mass, density));
    }
예제 #2
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Player" && !isTripped)
     {
         isTripped = true;
         WaveBehavior wav = Instantiate(wave);
         Destroy(gameObject);
     }
 }
예제 #3
0
    void Start()
    {
        //Get the water mesh
        waterMesh = this.GetComponent<MeshFilter>().mesh;

        originalVertices = waterMesh.vertices;

        //Get the waveScript
        GameObject gameController = GameObject.FindGameObjectWithTag("WaveManager");

        waveScript = gameController.GetComponent<WaveBehavior>();
    }
예제 #4
0
    new void Update()
    {
        switch (GetAggro())
        {
        case true:
            Aggressive();
            break;

        case false:
            Passive();
            break;
        }
        SetColor();
        if (GetHealth() <= 0)
        {
            //play particle and reward player
            if (GetAggro())
            {
                FindObjectOfType <EnemyCounterBehavior> ().SetCount(FindObjectOfType <EnemyCounterBehavior> ().GetCount() - 1);
            }
            Destroy(gameObject);
            return;
        }
        if (GetComponent <SpriteRenderer>().isVisible == false && isScared && hasBeenSeen)
        {
            WaveBehavior newWave    = Instantiate(wave);
            Vector2      newWavePos = transform.position - GetPlayer().transform.position;
            newWave.SetOffset(newWavePos.x, newWavePos.y + 2f, 0f);
            newWave.OnEnable();
            if (isEscaping)
            {
                Destroy(gameObject);
            }
            else
            {
                hasBeenSeen = false;
            }
        }
    }