コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        platformController = GetComponent <MovingPlatformController>();

        CalculateLiftBounds();
        player = GameObject.FindWithTag("Player").GetComponent <Player>();
    }
コード例 #2
0
 // Update is called once per frame
 void Update()
 {
     if (found)
     {
         if (!flyingUp)
         {
             MovingPlatformController movingScript = gameObject.GetComponent <MovingPlatformController>();
             if (movingScript != null)
             {
                 this.rigidbody.velocity = new Vector3(0, 0, 0);
             }
             movingScript.enabled = false;
             flyingUp             = true;
         }
         if (flyingUp)
         {
             this.rigidbody.AddForce(new Vector3(0, speedUP, 0));
             GameObject player = GameObject.FindGameObjectWithTag("Player");
             Debug.Log("distance = " + Vector3.Distance(this.transform.position, player.transform.position));
             if (Vector3.Distance(this.transform.position, player.transform.position) > minDistToVanish)
             {
                 Debug.Log("destruido...");
                 GameObject.Destroy(this.gameObject);
             }
         }
     }
 }
コード例 #3
0
    private void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag.Equals("MovingPlatform"))
        {
            Vector3 delta = transform.position - col.transform.position;

            if (delta.y > 0.6f)
            {
                onPlattform = true;
                tmpSpeed    = moveSpeed;
                MovingPlatformController movPlatCont = col.gameObject.GetComponent <MovingPlatformController>();
                moveSpeed             = tmpSpeed / movingPlatformDivider;
                this.transform.parent = col.transform;
            }
        }

        if (col.gameObject.tag.Equals("LeftWall"))
        {
            touchingLeftWall = true;
        }

        if (col.gameObject.tag.Equals("RightWall"))
        {
            touchingRightWall = true;
        }
    }
コード例 #4
0
    void HitSavePoint()
    {
        float   rayLength = collider_box.bounds.size.y;
        Vector2 rayOrigin = raycastOrigins.midBot;

        RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up, rayLength, collisionMask);

        //Debug.DrawRay(rayOrigin, Vector2.up, Color.red);
        if (hit && !saved)
        {
            player.savePoint = this.transform.position;
            foreach (GameObject b in box)
            {
                pushAble           = b.GetComponent <PushAble>();
                pushAble.savePoint = pushAble.transform.position;
            }
            foreach (GameObject m in movePlatform)
            {
                mpController = m.GetComponent <MovingPlatformController>();
                mpController.SavedPlatformMovement();
            }
            foreach (GameObject u in unStalePlatform)
            {
                usController = u.GetComponent <UnStablePlatformController>();
                usController.SaveIsHide();
            }
            saved = true;
        }
    }
コード例 #5
0
    void Start()
    {
        anim = GetComponentInChildren <Animation>();
        GameObject goParent = transform.parent.gameObject;

        //We need the controller of the moving platforms in order to activate them
        movingPlatformController = goParent.GetComponentInChildren <MovingPlatformController>();
    }
コード例 #6
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        startPos = platform1.transform.position;    //Set the starting position
    }
    void TargetOject()
    {
        switch (targetObject.tag)
        {
        case "MoveAble":
            mpController = targetObject.GetComponent <MovingPlatformController>();
            mpController.startFunction = false;
            break;

        case "PassAble":
            break;
        }
    }
コード例 #8
0
    public override void OnInspectorGUI()     //unity inspector tarafinda editoryel kismi acar.
    {
        MovingPlatformController script = (MovingPlatformController)target;

        if (GUILayout.Button("Add Point"))
        {
            GameObject newObject = new GameObject();
            newObject.transform.parent   = script.transform;           // platform nesnenim altinda nesneleri turetiyor.
            newObject.transform.position = script.transform.position;
            newObject.name = (script.transform.childCount).ToString(); //child kadar sayisi nesneme isim atar.
        }
        //EditorGUILayout.PropertyField(serializedObject.FindProperty("platformSpeed"));
    }
コード例 #9
0
    public override void OnInspectorGUI()                                       //the things drawn in the inspector box
    {
        MovingPlatformController controller = (MovingPlatformController)target; //the target is the instance of the MovingPlatformController script

        // Draw some stuff in the editor
        // Waypoint prefab
        controller.waypointPrefab = (GameObject)EditorGUILayout.ObjectField("Waypoint Object", controller.waypointPrefab, typeof(GameObject), false); //drag in the waypoint prefab to copy

        // Speed value
        controller.moveSpeed = EditorGUILayout.FloatField("Speed: ", controller.moveSpeed); //shows the speed value, and you can change it

        // Label for waypoints
        EditorGUILayout.LabelField("Waypoints", EditorStyles.boldLabel);

        //if there are waypoints, add them
        if (controller.waypoints != null && controller.waypoints.Count != 0) //it matters to check null before the count.
        {
            for (int i = 0; i < controller.waypoints.Count; i++)             //loop through waypoints
            {
                // Create horizontal groupings for each waypoint
                EditorGUILayout.BeginHorizontal();

                // Get the name of the game object for the label
                controller.waypoints[i].gameObject.name = EditorGUILayout.TextField(controller.waypoints[i].gameObject.name);

                controller.waypoints[i].position = EditorGUILayout.Vector2Field("", controller.waypoints[i].position);

                // Add a button to delete waypoint
                if (GUILayout.Button("Delete?")) //if you click on the button, perform action
                {
                    // Remove a specific waypoint (call controller for this)
                    controller.RemoveWaypoint(i);
                }

                EditorGUILayout.EndHorizontal();
            }
        }

        // Button to add waypoint
        if (GUILayout.Button("Add Waypoint")) //if you click on the button, perform action
        {
            // Add new waypoint to the waypoints list (tell the controller to add the waypoint)
            controller.AddNewWaypoint();
        }

        // Button to clear waypoints
        if (GUILayout.Button("Clear Waypoints"))
        {
            controller.ClearWaypoints(); //clears the list of waypoints
        }
    }
コード例 #10
0
    void CheckHit()
    {
        Bounds bounds    = this.collider_box.bounds;
        float  rayLength = bounds.size.x;

        for (int i = 0; i < horizontalRayCount; i++)
        {
            Vector2 rayOrigin = raycastOrigins.bottomLeft;
            rayOrigin += Vector2.up * (horizontalRaySpacing * i);
            RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right, rayLength, collisionMask);

            Debug.DrawRay(rayOrigin, Vector2.right, Color.red);

            if (hit)
            {
                audio.PlayOneShot(clip, 0.7F);
                player.GetSavePointPosition();
                player.velocity = Vector2.zero;
                foreach (GameObject b in box)
                {
                    pushAble = b.GetComponent <PushAble>();
                    pushAble.GetSavePointPosition();
                }
                foreach (GameObject m in movingPlatform)
                {
                    mpController = m.GetComponent <MovingPlatformController>();
                    mpController.ResetPlatformMovement();
                    mpController.loadedPlatformMovement();
                }
                foreach (GameObject u in unStalePlatform)
                {
                    usController = u.GetComponent <UnStablePlatformController>();
                    usController.IsThisHide();
                }
            }
        }
    }
コード例 #11
0
    // Update is called once per frame
    void Update()
    {
        float deltaX = 0;

        deltaX = Input.GetAxis("Horizontal") * speed * Time.deltaTime;

        Vector2 movement = new Vector2(deltaX, _body.velocity.y);

        _body.velocity = movement;

        Vector3    max      = _box.bounds.max;
        Vector3    min      = _box.bounds.min;
        Vector2    corner1  = new Vector2(max.x, min.y - 0.1f);
        Vector2    corner2  = new Vector2(max.x, min.y - 0.2f);
        Collider2D hit      = Physics2D.OverlapArea(corner1, corner2);
        bool       grounded = false;

        if (hit != null)
        {
            grounded = true;
        }


        if (Input.GetKeyDown(KeyCode.Space))
        {
            _body.gravityScale = 1.4f;

            if (grounded)
            {
                _body.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
            }
        }


        MovingPlatformController platform = null;

        if (hit != null)
        {
            platform = hit.GetComponent <MovingPlatformController>();
        }


        if (platform != null)
        {
            transform.parent = platform.transform;
        }
        else
        {
            transform.parent = null;
        }


        _ani.SetFloat("speed", Mathf.Abs(deltaX));

        Vector3 pScale = Vector3.one;

        if (platform != null)
        {
            pScale = platform.transform.localScale;
        }
        if (deltaX != 0)
        {
            transform.localScale = new Vector3(Mathf.Sign(deltaX) / pScale.x, 1 / pScale.y, 1);
        }
    }
コード例 #12
0
 void Start()
 {
     mPC = GameObject.Find(mpName).GetComponent <MovingPlatformController>();
 }
コード例 #13
0
ファイル: PlatformTrigger.cs プロジェクト: IpursueI/Wonambi
 private void Awake()
 {
     moveController = transform.parent.gameObject.GetComponent <MovingPlatformController>();
 }