Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

problem with the collider or mistake

Discussion in 'Editor & General Support' started by aravind1971, Feb 14, 2018.

  1. aravind1971

    aravind1971

    Joined:
    Sep 14, 2017
    Posts:
    2
    Hi, i really want to know whether there is a problem with collision or my script, in my short project a sprite will move from bottom to top but it isnt being detected when colliding with a static body, and the code for both for the water movement script and end script is below
    WatMov.cs :
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class WaterMov : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    transform.position+=(new Vector3(0.0f,(transform.position.y)*-0.50f*Time.deltaTime,0.0f));
    Debug.Log ("X position:" + transform.position.x);
    Debug.Log ("Y position:" + transform.position.y);
    Debug.Log ("Z position:" + transform.position.z);
    }
    }


    stageEnd.cs:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class stageEnd : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
    void OnCollisionEnter2D(Collision2D colbj)
    {
    if (colbj.gameObject.tag =="objective")
    {
    Debug.Log ("entered");
    Time.timeScale = 0;
    }
    }
    }
     

    Attached Files:

    • stageEnd.cs
      File size:
      416 bytes
      Views:
      625
    • WaterMov.cs
      File size:
      512 bytes
      Views:
      684
    • 1.png
      1.png
      File size:
      597.9 KB
      Views:
      652
    • 2.png
      2.png
      File size:
      597.1 KB
      Views:
      674
    • 3.png
      3.png
      File size:
      523.2 KB
      Views:
      664
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Where's your rigidbody2d components? I believe those are required unless you are using trigger colliders.
     
  3. aravind1971

    aravind1971

    Joined:
    Sep 14, 2017
    Posts:
    2
    it is already present for the moving object aka the water sprite
     

    Attached Files:

    • 4.png
      4.png
      File size:
      566.4 KB
      Views:
      661