コード例 #1
0
    void Update()
    {
        rot_axis.Normalize();
        Quaternion q = Quaternion.AngleAxis(Time.deltaTime * rot_speed, rot_axis);

        this.transform.rotation *= q;
        Vector3 forward = this.transform.rotation * new Vector3(0, 1, 0);

        if (axis != null)
        {
            Vector3 up = new Vector3(0, 1, 0);
            q = Quaternion.FromToRotation(up, rot_axis);
            axis.transform.rotation = q;
        }

        RaycastHit hit;

        if (Physics.Raycast(transform.position, forward, out hit, Mathf.Infinity))
        {
            //Debug.DrawRay(transform.position, forward * hit.distance, Color.red);
            //Debug.Log("Did Hit");
            if (hit_sphere != null)
            {
                hit_sphere.SetActive(true);
                hit_sphere.transform.position = transform.position + forward * hit.distance;
            }

            GameObject      obj = hit.transform.gameObject;
            TouchableSphere ts  = obj.GetComponent <TouchableSphere>();
            if (ts != null)
            {
                ts.highlight(forward * 4);
            }
        }
        else
        {
            if (hit_sphere != null)
            {
                hit_sphere.SetActive(false);
            }
        }
    }
コード例 #2
0
    void Start()
    {
        all_spheres = new List <GameObject>();

        float asteps = Mathf.PI * 2 / equator_steps;

        for (int y = -y_steps; y <= y_steps; ++y)
        {
            float py = 0;
            if (y_steps != 0)
            {
                py = (y * 1f / y_steps) * inner_radius;
            }

            for (float a = 0; a < Mathf.PI * 2; a += asteps)
            {
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                sphere.transform.parent   = this.transform;
                sphere.transform.position = new Vector3(
                    Mathf.Cos(a) * inner_radius,
                    py,
                    Mathf.Sin(a) * inner_radius
                    );
                sphere.transform.localScale = new Vector3(sphere_radius, sphere_radius, sphere_radius);
                sphere.AddComponent <SphereCollider>();

                //Rigidbody rb = sphere.AddComponent<Rigidbody>();
                //rb.useGravity = false;

                TouchableSphere ts = sphere.AddComponent <TouchableSphere>();
                ts.normal_mat    = normal_mat;
                ts.highlight_mat = highlight_mat;

                if (normal_mat != null)
                {
                    sphere.GetComponent <Renderer>().material = normal_mat;
                }
            }
        }
    }